Learn R Programming

brms (version 0.3.0)

ranef: Extract Random Effects for brmsfit objects

Description

A generic function to extract the random effects of each level from a fitted model object.

Usage

## S3 method for class 'brmsfit'
ranef(x, estimate = "mean", var = FALSE, center.zero = TRUE, ...)

Arguments

x
An object of a class of fitted models with random effects, typically a brmsfit object.
estimate
The point estimate to be calculated for the random effects, either "mean" or "median".
var
logical; indicating if the covariance matrix for each random effects should be computed.
center.zero
logical; indicating if the random effects are centered around the corresponding fixed effect (if present) or around zero (the default).
...
Further arguments to be passed to the function specified in estimate

Value

  • A list of matrices (one per grouping factor), each with one row per level and one single column for the estimate (either mean or median).

Examples

Run this code
fit_e <- brm(count ~ log_Age_c + log_Base4_c * Trt_c + (1+Trt_c|visit),
             data = epilepsy, family = "poisson", n.chains = 1)
## random effects means centered around zero with corresponding covariances
rf <- ranef(fit_e, var = TRUE)
attr(rf, "var")
## random effects medians centered around the corresponding fixed effect
ranef(fit_e, estimate = "median", center.zero = FALSE)

Run the code above in your browser using DataLab