extract_het_var: Extract heterogeneous variances

View source: R/extract_het_var.R

extract_het_varR Documentation

Extract heterogeneous variances

Description

Extract heterogeneous variances for nlme, glmmTMB, and brms models.

Usage

extract_het_var(model, digits = 3, scale = "var", ...)

## S3 method for class 'lme'
extract_het_var(model, digits = 3, scale = "var", ...)

## S3 method for class 'glmmTMB'
extract_het_var(model, digits = 3, scale = "var", ...)

## S3 method for class 'brmsfit'
extract_het_var(
  model,
  digits = 3,
  scale = "var",
  ...,
  ci_level = 0.95,
  return_all = FALSE
)

Arguments

model

An appropriate mixed model.

digits

Rounding. Default is 3.

scale

Return result on original standard deviation scale ('sd') or as variance ('var'), the default.

...

Other arguments specific to the method. Unused at present.

ci_level

For brms objects, confidence level < 1, typically above 0.90. A value of 0 will not report it. Default is .95.

return_all

For brms class objects, return all fitted values (TRUE) or only the distinct ones. Default is FALSE.

Details

For nlme models with heterogeneous variance, i.e. that contain something like varIdent(form = ~1|Group), this returns a more presentable version the estimates. Only tested with the varIdent case.

For glmmTMB, this serves as a wrapper for extract_cor_structure for models with for the diag function as part of the formula. See that function for details. For distributional models where the dispersion is explicitly modeled separately via disp = ~ , use the component argument of the other functions in this package.

For brms distributional models with a sigma ~ . formula, this produces the (unique) fitted values for the dispersion part of the model. As this is often just a single grouping variable to allow variance to vary over the group levels, only the distinct fitted values, which would be one value per group, are returned. If all fitted values are desired, set return_all to TRUE.

This function has not been tested except in the more simple model settings. It's unclear how well it will work with other model complications added.

Value

A vector of the estimates on the variance scale

See Also

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

Examples

library(nlme)
library(mixedup)

model <- lme(
  distance ~ age + Sex,
  data = Orthodont,
  random = ~ 1|Subject,
  weights = varIdent(form = ~ 1 | Sex)
)

summary(model)

extract_het_var(model)

library(glmmTMB)

# does not get the same estimates as nlme, but would get similar if modeled
# using dispersion approach.
model <-
  glmmTMB(distance ~ age + Sex + (1 | Subject) + diag(Sex + 0 | Subject),
          data = Orthodont)

extract_het_var(model)

# compare with
model <-
  glmmTMB(distance ~ age + Sex + (1 | Subject), dispformula = ~ Sex,
          data = Orthodont)

extract_fixed_effects(model, component = 'disp', exponentiate = TRUE)

## Not run: 
library(brms)

model <-
  brm(bf(distance ~ age + Sex + (1 | Subject), sigma ~ Sex),
      data = Orthodont)

extract_het_var(model)

## End(Not run)


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