extract_vc: Extract variance components

View source: R/extract_vc.R

extract_vcR Documentation

Extract variance components

Description

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

Usage

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

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

## S3 method for class '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 class '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 class '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 class 'stanreg'
extract_vc(
  model,
  ci_level = 0.95,
  ci_args = NULL,
  ci_scale = "sd",
  show_cor = FALSE,
  digits = 3,
  component = NULL,
  ...
)

## S3 method for class '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.

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.

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.

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

See Also

lme4::confint.merMod(), lme4::VarCorr(), glmmTMB::VarCorr(), nlme::intervals(), nlme::VarCorr(), brms::VarCorr(), rstanarm::VarCorr(), mgcv::gam.vcomp()

Other extract: extract_cor_structure(), extract_fixed_effects(), extract_het_var(), extract_model_data(), extract_random_coefs(), extract_random_effects()

Examples

library(lme4)
library(mixedup)

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

extract_vc(lmer_mod)
extract_vc(lmer_mod, ci_scale = 'var')


m-clark/mixedup documentation built on Oct. 15, 2022, 8:55 a.m.