Extracts the random effects and their standard errors.

extract_random_effects(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  add_group_N = FALSE,
  component = NULL,
  ...
)

# S3 method for merMod
extract_random_effects(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  add_group_N = FALSE,
  ...
)

# S3 method for glmmTMB
extract_random_effects(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  add_group_N = FALSE,
  component = "cond",
  ...
)

# S3 method for lme
extract_random_effects(
  model,
  re = NULL,
  ci_level = NULL,
  digits = 3,
  add_group_N = FALSE,
  ...
)

# S3 method for brmsfit
extract_random_effects(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  add_group_N = FALSE,
  component = NULL,
  ...
)

# S3 method for stanreg
extract_random_effects(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  add_group_N = FALSE,
  component = NULL,
  ...
)

# S3 method for gam
extract_random_effects(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  add_group_N = FALSE,
  ...
)

extract_ranef(
  model,
  re = NULL,
  ci_level = 0.95,
  digits = 3,
  add_group_N = FALSE,
  component = NULL,
  ...
)

Arguments

model

An appropriate model. See details.

re

The name of the grouping variable for the random effects. Default is NULL to return all.

ci_level

Where possible, confidence level < 1, typically above 0.90. A value of 0 will not report it. Default is .95. Not applicable to nlme objects.

digits

Rounding. Default is 3.

add_group_N

Add group sample sizes to output? Default is FALSE.

component

For glmmTMB objects, which of the two components 'cond' or 'zi' to select. Default is 'cond'. For brmsfit objects, this can filter results to a certain part of the output, e.g. 'sigma' or 'zi' of distributional models, or a specific outcome name of a multivariate model. In this case component is a regular expression that ends the name of the parameters of the output (e.g. '__component').

...

Other arguments specific to the method. Unused at present.

Value

data frame of the random effects

Details

Relative to ranef for the various packages, this just adds the standard errors and cluster ids as columns, and uncertainty intervals.

Current models supported:

merMod

glmmTMB

brms

nlme

brms

rstanarm

mgcv

Note

The nlme package only provides the estimated random effect parameters, not their uncertainty, so it isn't provided.

merMod and glmmTMB objects results are based on the estimated conditional variances, i.e. condvar = TRUE. This is likely an underestimate relative to brms results.

For mgcv, the Vp (Bayesian) estimated variance covariance matrix is used.

extract_ranef is an alias.

See also

Examples

library(lme4) library(mixedup) lmer_model <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy) extract_random_effects(lmer_model)
#> # A tibble: 36 x 7 #> group_var effect group value se lower_2.5 upper_97.5 #> <chr> <chr> <fct> <dbl> <dbl> <dbl> <dbl> #> 1 Subject Intercept 308 2.26 12.1 -21.4 25.9 #> 2 Subject Intercept 309 -40.4 12.1 -64.1 -16.7 #> 3 Subject Intercept 310 -39.0 12.1 -62.6 -15.3 #> 4 Subject Intercept 330 23.7 12.1 0.032 47.3 #> 5 Subject Intercept 331 22.3 12.1 -1.40 45.9 #> 6 Subject Intercept 332 9.04 12.1 -14.6 32.7 #> 7 Subject Intercept 333 16.8 12.1 -6.82 40.5 #> 8 Subject Intercept 334 -7.23 12.1 -30.9 16.4 #> 9 Subject Intercept 335 -0.334 12.1 -24.0 23.3 #> 10 Subject Intercept 337 34.9 12.1 11.2 58.5 #> # … with 26 more rows