Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
R2 is a useful tool for determining how strong the relationship between two variables is. Unfortunately, the definition of R2 for mixed effects models is difficult – do you include the random variable or just the fixed effects? Including just the fixed effects is essentially a standard linear model, while including the random effects could confuse some readers (you have a much higher R2). So which do you report? Nakagawa and Schielzeth (2013) say both! They even provide the formulae for their calculation.
Over on the sample(ECOLOGY) blog, an R function has been written for lme and lmer models and reports both R2 based on just the fixed effects (marginal R2) and that incorporating the random effects (conditional R2). Simply go to the link, copy the code into the console, hit enter and give the function a list of your models.
e.g. (from the sample(ECOLOGY) page)
Example mod1=lmer(rnorm(100,5,10)~rnorm(100,20,100)+(1|rep(c("A","B"),50))) mod2=lmer(rnorm(100,5,10)~rnorm(100,20,100)+rnorm(100,0.5,2)+(1|rep(c("A","B"),50))) rsquared.lme(list(mod1,mod2))
A couple of warnings for lmer users though:
- you might have to tweak the code if you only have a single random effect for in lmer models. If you have multiple random effect levels or lme models, you should be fine
- the function is currently written for “mer” class models from lmer – the newer development versions of lmer use the “merMod” class and do away with @ as a slot
UPDATE: The function name has been changed to rsquared.glmm(). It now also handles models with poisson and binomial models. I think that lmer issues have been solved now too.
Nakagawa, S., and H. Schielzeth. 2013. A general and simple method for obtaining R2 from generalized linear mixed-effects models. Methods in Ecology and Evolution 4(2): 133-142.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.