This has functionality for simpler models from lme4, glmmTMB, nlme, and brms.

extract_vc(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  ...
)

# S3 method for merMod
extract_vc(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  ...
)

# S3 method for glmmTMB
extract_vc(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  component = "cond",
  include_het_var = FALSE,
  ...
)

# S3 method for lme
extract_vc(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  include_het_var = FALSE,
  ...
)

# S3 method for brmsfit
extract_vc(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  component = NULL,
  include_het_var = FALSE,
  ...
)

# S3 method for stanreg
extract_vc(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  component = NULL,
  ...
)

# S3 method for gam
extract_vc(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  ...
)

extract_variance_components(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  ...
)

extract_VarCorr(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  ...
)

Arguments

model

An lme4, glmmTMB, nlme, mgcv, or brms model.

ci_level

Confidence level < 1, typically above 0.90. A value of 0 will not report it (except for gam objects, which will revert to .95 due to gam.vcomp). Default is .95.

ci_args

Additional arguments to the corresponding confint method.

ci_scale

A character string of 'sd' or 'var' to note the scale of the interval estimate. Default is 'sd'. at present.

show_cor

Return the intercept/slope correlations as a separate list element. Default is FALSE.

digits

Rounding. Default is 3.

...

Other stuff to pass to the corresponding method.

component

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

include_het_var

For models for which extract_het_var can be applied, this will return a list object including it.

Value

A data frame with output for variance components, or list that also contains the correlations of the random effects and/or the heterogeneous variances.

Details

Returns a more usable (my opinion) version of variance components estimates including variance, standard deviation, the confidence interval for either, the relative proportion of variance, and all in a data frame with names that are clean and easy to use.

extract_variance_components and extract_VarCorr are aliases.

Note

Right now, there are several issues with getting confidence intervals for glmmTMB objects (for example, which is actually not resolved). If you get an error or unexpected results, you should check by running confint(my_tmb_model) before posting an issue. While I've attempted some minor hacks to deal with some of them, it stands to reason that if the glmmTMB functionality doesn't work, this function won't either. You should be fine for standard mixed models

Examples

library(lme4)
library(mixedup)

lmer_mod <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)

extract_vc(lmer_mod)
#> Computing profile confidence intervals ...
#>                           group    effect variance     sd sd_2.5 sd_97.5
#> sd_(Intercept)|Subject  Subject Intercept  612.100 24.741 14.381  37.716
#> sd_Days|Subject         Subject      Days   35.072  5.922  3.801   8.753
#> sigma                  Residual            654.940 25.592 22.898  28.858
#>                        var_prop
#> sd_(Intercept)|Subject    0.470
#> sd_Days|Subject           0.027
#> sigma                     0.503
extract_vc(lmer_mod, ci_scale = 'var')
#> Computing profile confidence intervals ...
#>                           group    effect variance     sd var_2.5 var_97.5
#> sd_(Intercept)|Subject  Subject Intercept  612.100 24.741 206.826 1422.496
#> sd_Days|Subject         Subject      Days   35.072  5.922  14.449   76.621
#> sigma                  Residual            654.940 25.592 524.331  832.784
#>                        var_prop
#> sd_(Intercept)|Subject    0.470
#> sd_Days|Subject           0.027
#> sigma                     0.503