Learn R Programming

mlmtools (version 1.0.2)

varCompare: Compares variance explained for two mixed effects models

Description

Compares variance explained by additional fixed effects for two lme4-fitted mixed-effects models.

Usage

varCompare(model1, model2)

Value

Computes the percent increase in variance explained by the less parsimonious (more complicated) model compared to the more parsimonious (less complicated) model.

Arguments

model1

A linear mixed-effects model of class lmerMod or lmerModLmerTest

model2

A linear mixed-effects model of class lmerMod or lmerModLmerTest

Details

Specifically, 1-(total variance for less parsimonious model/total variance for more parsimonious model).

References

Snijders, T. A. B. & Bosker, R. J. (2012). Multilevel Analysis (2nd Ed.). Sage Publications Ltd.

Examples

Run this code
# Read in data
data(instruction)
# Create null model
mod0 <- lme4::lmer(mathgain ~ (1 | classid), data = instruction)
# Create model of interest
mod1 <- lme4::lmer(mathgain ~ mathkind + (1 | classid), data = instruction)
# Compare variance explained
### To repress output: use invisible()
varCompare(mod0, mod1)

Run the code above in your browser using DataLab