rsqmlm {mlmtools} | R Documentation |
Calculates R-squared from lmer models
Description
Calculates variance explained by lme4-fitted mixed-effects models.
Usage
rsqmlm(model, by_cluster = FALSE)
Arguments
model |
A linear mixed-effects model of class lmerMod or lmerModLmerTest |
by_cluster |
Logical, if TRUE returns variance explained at each level |
Value
Computes the percent variance explained by the model.
References
Nakagawa, S., Johnson, P. C., & Schielzeth, H. (2017). The coefficient of determination R 2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded. Journal of the Royal Society Interface, 14(134), 20170213.
Examples
# Read in data
data(instruction)
# Center mathkind by classid
center(dataset = instruction, x = "mathkind", grouping = "classid")
# Create model
mod <- lme4::lmer(mathgain ~ classid_mathkind.cmn +
classid_mathkind.devcmn + (1 | classid), data = instruction)
# Calculate r-squared
### To repress output: use invisible()
rsq <- rsqmlm(mod)
rsq
rsq$marginal
rsq$conditional
[Package mlmtools version 1.0.2 Index]