rsqmlm | R Documentation |
Calculates variance explained by lme4-fitted mixed-effects models.
rsqmlm(model, by_cluster = FALSE)
model |
A linear mixed-effects model of class lmerMod or lmerModLmerTest |
by_cluster |
Logical, if TRUE returns variance explained at each level |
Computes the percent variance explained by the model.
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.
# Gaussian ## 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 # Logistic ## Read in data data(reporting) ## Create model mod <- lme4::glmer(mention.outliers ~ Basics + (1 | Journal), data = reporting, family = "binomial") ## Calculate r-squared ### To repress output: use invisible() rsq <- rsqmlm(mod) rsq rsq$marginal rsq$conditional
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.