I do not know if this has been asked before, but I do not found anything about it. My question is if anyone can provide a good reference to learn how to obtain the proportion of variance explained by each one of the fixed and random factors in a mixed-effects model.
-
4$\begingroup$ Good question, but I don't have (a reference for) a good answer. There's more than one level of variation in mixed models, so there's more than one component of variance to explain, plus it's debateable whether random effects can really be said to 'explain' variance. I think the whole concept of 'proportion of variance explained' is less useful in mixed models. $\endgroup$– onestopCommented Feb 15, 2011 at 9:18
-
$\begingroup$ Here is some more discussion on the topic: stat.ethz.ch/pipermail/r-sig-mixed-models/2010q1/003363.html $\endgroup$– user5475Commented Jul 19, 2011 at 19:49
-
1$\begingroup$ Gelmans "Bayesian ANOVA" approach might also be useful. $\endgroup$– N BrouwerCommented May 3, 2017 at 13:22
-
$\begingroup$ you can use glmm.hp function in glmm.hp package in R $\endgroup$– jiangshan laiCommented Apr 3, 2022 at 3:14
-
$\begingroup$ The fraction of variance explained by the random factors should be independent of their scaling but the variance estimates for the random effects depend on their scaling. Look into page 18("2") eq.2 of S1 of doi:10.1038/nmeth.4636 or limix's normalise_covariance function to learn about one way to deal with this. $\endgroup$– jan-glxCommented Mar 15 at 9:37
3 Answers
I can provide some references:
Xu, R. (2003). Measuring explained variation in linear mixed effects models. Statistics in Medicine, 22, 3527-3541. DOI:10.1002/sim.1572
Edwards, L. J., Muller, K. E., Wolfinger, R. D., Qaqish, B. F., & Schabenberger, O. (2008). An $R^2$ statistic for fixed effects in the linear mixed model. Statistics in Medicine, 27, 6137-6157. DOI:10.1002/sim.3429
Hössjer, O. (2008). On the coefficient of determination for mixed regression models. Journal of Statistical Planning and Inference, 138, 3022-3038. DOI:10.1016/j.jspi.2007.11.010
Nakagawa, S., & Schielzeth, H. (2013). A general and simple method for obtaining $R^2$ from generalized linear mixed-effects models. Methods in Ecology and Evolution, 4, 133-142. DOI:10.1111/j.2041-210x.2012.00261.x
Happy reading!
According to this blog post from 2013, the MuMIn
package in R
can provide R$^2$ values for mixed models ala an approach developed by Nakagawa & Schielzeth 2013$^1$ (which was mentioned in a previous answer).
#load packages
library(lme4)
library(MuMIn)
#Fit Model
m <- lmer(mpg ~ gear + disp + (1|cyl), data = mtcars)
#Determine R2:
r.squaredGLMM(m)
R2m R2c
0.5476160 0.7150239
The output for functionr.squaredGLMM
provides:
R2m: marginal R squared value associated with fixed effects
R2c conditional R2 value associated with fixed effects plus the random effects.
Note: a comment on the linked blog post suggests that an alternative Nakagawa & Schielzeth inspired approach developed by Jon Lefcheck (using the sem.model.fits
function in the piecewiseSEM
package) produced identical results. [So you have options :p].
I did not test this latter function, but I did test the
r.squaredGLMM()
function in theMuMIn
package and so can attest that it is still functional today (2018).As for the validity of this approach, I leave reading Nakagawa & Schielzeth (2013) (and follow-up article Johnson 2014$^2$) up to you.
1: Nakagawa, S., and Schielzeth, H. 2013. A general and simple method for obtaining R2 from generalized linear mixed‐effects models. Methods in Ecology and Evolution 4(2): 133-142.
2: Johnson, P. C. D. 2014 Extension of Nakagawa & Schielzeth’s R2GLMM to random slopes models. Methods in Ecology and Evolution 5: 44–946.
-
1$\begingroup$ Thanks @theforestecologist for your answer. I will have a look to the mentioned packages. $\endgroup$ Commented May 25, 2018 at 5:47
The recently published work Shaw, M., Rights, J.D., Sterba, S.S. et al. r2mlm: An R package calculating R-squared measures for multilevel models. Behav Res 55, 1942–1964 (2023). seems to provide Variance explained analyses for models with with lme4 through the R package r2mlm