extract_cor_structure: Extract correlation structure

View source: R/extract_cor_structure.R

extract_cor_structureR Documentation

Extract correlation structure

Description

Extract residual correlation structure for nlme, brms, and glmmTMB models.

Usage

extract_cor_structure(model, digits = 3, ...)

## S3 method for class 'lme'
extract_cor_structure(model, digits = 3, ...)

## S3 method for class 'glmmTMB'
extract_cor_structure(
  model,
  digits = 3,
  ...,
  component = "cond",
  which_cor,
  full_matrix = FALSE
)

## S3 method for class 'brmsfit'
extract_cor_structure(model, digits = 3, ..., ci_level = 0.95)

Arguments

model

An appropriate mixed model.

digits

Rounding. Default is 3.

...

Other arguments specific to the method. Unused at present.

component

For glmmTMB objects, which of the three components 'cond', 'zi' or 'disp' to select. Default is 'cond'.

which_cor

Required for glmmTMB. Which correlation parameter to extract. Must be one of 'ar1', 'ou', 'cs', 'toep', 'diag','us', 'mat', 'gau', 'exp'.

full_matrix

For glmmTMB correlation, return the full residual covariance/correlation matrix (TRUE), or simplified output where possible (FALSE). Default is FALSE. See details.

ci_level

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

Details

This function applies to models with residual correlation, i.e. that contain something like corAR1(form = ~time) for nlme, or brms models with an something like ar() in the formula. This functions extracts the associated parameters (e.g. Phi in nlme, ar[1] in brms, etc.)

For glmmTMB objects, rather than the full matrix, simplified output is provided by default. For ar1, ou, cs, a single value; for toep (toeplitz) a single row/column; for diag structures just the diagonal. In addition, for diag the residual variance is added to the estimates.

For more detail, see this 'braindump' from Ben Bolker, and the glmmTMB vignette.

Most types of spatial models should work as well.

Value

For nlme and glmmTMB models, a data frame of the estimates. For brms, the parameters and related uncertainty, similar to extract_fixed_effects.

See Also

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

Examples

## Not run: 
library(brms)
library(mixedup)

brm_corAR <- brm(
  Reaction ~ Days + (Days | Subject),
  autocor = cor_ar( ~ Days | Subject),
  save_ranef = FALSE,
  cores = 4,
  thin = 40
)

extract_cor_structure(brm_corAR)

## End(Not run)


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