| R2_model | R Documentation |
The R-squared of a model as a numeric result, for every model class of predictmeans. method = "piepho" (the default) gives the same values as
R2_glmm() of predictmeans 1.x (removed in 2.0; Piepho, 2023), as proportions: total, fixed, random and
each random-effect component.
method = "nakagawa" gives the marginal (fixed effects) and conditional (fixed and random effects) R-squared of
Nakagawa and Schielzeth (2013), with random slopes as Johnson (2014): the variance of each random-effect term is the
mean of z_i' \Sigma z_i over the observations.
R2_model(model, method = c("piepho", "nakagawa"), over_disp = FALSE)
model |
A model of any class |
method |
|
over_disp |
For |
Piepho's R-squared is one definition for every class: the variance of the fixed part of the model (less the bias from
estimating the coefficients) and of the random effects, as shares of the average variance of the data. For models
without random effects (lm, aov, glm, gls) Total equals Fixed and
Random is 0; for lm and aov it is the usual adjusted R-squared. glm models are
measured on the link scale (working variances; the latent distribution for a binary response); gls and
lme models with any correlation and variance structure; aov models with Error() from the
stratum variance components of varcomp. In gam models the smooths are part of the fixed share,
except random-effect smooths (bs = "re").
For "nakagawa" the observation-level variance is the residual variance for gaussian models and the variance
of the latent distribution for binomial models: \pi^2/3 (logit), 1 (probit) or \pi^2/6 (cloglog). Other
families have several competing approximations; use method = "piepho" for them.
A named numeric vector of proportions (class "pm_r2", printed as percentages). For "nakagawa",
Marginal and Conditional, with attribute "variances": the fixed-effect, random-effect and
observation-level variances. The Nakagawa values agree with performance::r2_nakagawa()
(‘tests/testthat/test-r2-model.R’). Notes on the choice of method are kept in attr(, "advice")
(advice).
Dongwen Luo, Siva Ganesh and John Koolaard
Piepho, H.-P. (2023), An adjusted coefficient of determination (R2) for generalized linear mixed models in one go, Biometrical Journal, 65(7), 2200290.
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, 133-142.
Johnson, P. C. D. (2014), Extension of Nakagawa & Schielzeth's R2GLMM to random slopes models, Methods in Ecology and Evolution, 5, 944-946.
varcomp, advice
library(predictmeans)
fm <- lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy)
R2_model(fm)
R2_model(fm, "nakagawa")
R2_model(lm(Reaction ~ Days, data = sleepstudy)) # the adjusted R-squared
R2_model(glm(breaks ~ wool*tension, family = poisson, data = warpbreaks))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.