lvl2_var_cond_lvl1: Variance between level 2 units at different values of level 1...

View source: R/lvl2_var_cond_lvl1.R

lvl2_var_cond_lvl1R Documentation

Variance between level 2 units at different values of level 1 variables.

Description

Variance between level 2 units at different values of level 1 variables.

Usage

lvl2_var_cond_lvl1(model, lvl1.var, lvl1.values)

Arguments

model

Mixed effect model fitted with lmer. Must include random intercept, slope, and their covariation.

lvl1.var

Level 1 variable name.

lvl1.values

Level 1 variable values.

Value

Data frame of level 2 variance estimates conditioned on level 1 variable values.

Examples

cdat <- group_mean_center(
  data = iris,
  vars = c(
    "Sepal.Length",
    "Sepal.Width",
    "Petal.Length",
    "Petal.Width"
  ),
  group.var = "Species",
  grand.init = TRUE
)

fit <- lme4::lmer(Sepal.Length ~ Petal.Length.gmc + (Petal.Length.gmc | Species),
  data = cdat, REML = FALSE
)

lvl2_var_cond_lvl1(
  model = fit,
  lvl1.var = "Petal.Length.gmc",
  lvl1.values = c(-2, -1, 0, 1, 2)
)

vjilmari/vjihelpers documentation built on May 23, 2022, 6:43 p.m.