extract_vc: Extract variance components

Description Usage Arguments Details Value Examples

View source: R/extract_vc.R

Description

This function extracts the variance components from a gam or bam object, where one is using the associated functions from the mgcv package for mixed models.

Usage

1
extract_vc(model, ci_level = 0.95, ci_scale = "sd", digits = 3)

Arguments

model

A gam or bam model

ci_level

Level for the confidence interval. Must be between 0 and 1.

ci_scale

Whether the confidence interval should be on the variance or standard deviation scale.

digits

Rounding for the output.

Details

This is essentially a pretty way to print gam.vcomp. Note that if you do something like a random slope, the gam approach does not estimate the intercept-slope correlation, so none will be printed. Should work fine on standard smooth terms also, but the model must be estimated with method = REML or method = ML. This is the default for non-exponential families, but otherwise you'll have to change the value or will receive an error. Have not tested much with interactions, using by, etc., but it has worked on some default mgcv examples.

Value

A tibble or data frame with the standard deviation, its lower and upper bounds, the variance, and the relative proportion of total variance for each variance component.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
library(mgcv)
library(lme4)

lmer_model <- lmer(Reaction ~ Days + (Days || Subject), data = sleepstudy)
ga_model <- gam(Reaction ~ Days + s(Subject, bs = "re") + s(Days, Subject, bs = "re"),
  data = sleepstudy,
  method = "REML"
)

VarCorr(lmer_model)
extract_vc(ga_model)

m-clark/gammit documentation built on Oct. 22, 2020, 6:53 p.m.