estimate_grouplevel {modelbased} | R Documentation |
Group-specific parameters of mixed models random effects
Description
Extract random parameters of each individual group in the context of mixed models, commonly referred to as BLUPs (Best Linear Unbiased Predictors). Can be reshaped to be of the same dimensions as the original data, which can be useful to add the random effects to the original data.
Usage
estimate_grouplevel(model, ...)
## Default S3 method:
estimate_grouplevel(model, type = "random", ...)
## S3 method for class 'brmsfit'
estimate_grouplevel(
model,
type = "random",
dispersion = TRUE,
test = NULL,
diagnostic = NULL,
...
)
reshape_grouplevel(x, ...)
## S3 method for class 'estimate_grouplevel'
reshape_grouplevel(x, indices = "all", group = NULL, ...)
Arguments
model |
A mixed model with random effects. |
... |
Other arguments passed to |
type |
|
dispersion , test , diagnostic |
Arguments passed to
|
x |
The output of |
indices |
A character vector containing the indices (i.e., which columns) to extract (e.g., "Coefficient", "Median"). |
group |
The name of the random factor to select as string value (e.g.,
|
Details
Unlike raw group means, BLUPs apply shrinkage: they are a compromise between the group estimate and the population estimate. This improves generalizability and prevents overfitting.
Examples
# lme4 model
data(mtcars)
model <- lme4::lmer(mpg ~ hp + (1 | carb), data = mtcars)
random <- estimate_grouplevel(model)
# Show group-specific effects
random
# Visualize random effects
plot(random)
# Reshape to wide data...
reshaped <- reshape_grouplevel(random, group = "carb", indices = c("Coefficient", "SE"))
# ...and can be easily combined with the original data
alldata <- merge(mtcars, reshaped)
# overall coefficients
estimate_grouplevel(model, type = "total")