r.squaredGLMM.Rd
Calculate conditional and marginal coefficient of determination for Generalized mixed-effect models (GLMM).
r.squaredGLMM(object, null, ...)
# S3 method for class 'merMod'
r.squaredGLMM(object, null, envir = parent.frame(), pj2014 = FALSE, ...)
a fitted linear model object.
optionally, a null model, including only random effects. See ‘Details’.
optionally, the environment
in which the null model is to be evaluated.
Defaults to the current frame. See eval
.
logical, if TRUE
and object
is of poisson
family, the result will include GLMM using original formulation of
Johnson (2014). This requires fitting object
with an observation-level
random effect term added.
additional arguments, ignored.
r.squaredGLMM
returns a two-column numeric matrix
, each (possibly
named) row holding values for marginal and conditional GLMM
calculated with different methods, such as “delta”,
“log-normal”, “trigamma”, or “theoretical” for models
of binomial
family.
There are two types of GLMM: marginal and conditional.
Marginal GLMM represents the variance explained by the fixed effects, and is defined as:
R_GLMM(m)^2= _f^2_f^2 + _^2 + _ ^2 R_GLMM(m)² = (_f²) / (_f² + _² + _²) R_GLMM(m)^2 = (sigma_f^2) / (sigma_f^2 + sigma_alpha^2 + sigma_epsilon^2)
Conditional GLMM represents the variance explained by the entire model, including both fixed and random effects. It is calculated by the equation:
R_GLMM(c)^2= _f^2 + _^2_f^2 + _^2 + _ ^2 R_GLMM(c)² = (_f² + _²) / (_f² + _² + _²) R_GLMM(c)^2 = (sigma_f^2 + sigma_alpha^2) / (sigma_f^2 + sigma_alpha^2 + sigma_epsilon^2)
where _f^2_f²sigma_f^2 is the variance of the fixed effect components, __²sigma_alpha^2 is the variance of the random effects, and _^2_²sigma_epsilon^2 is the “observation-level” variance.
Three methods are available for deriving the observation-level variance \(\sigma_\varepsilon\): the delta method, lognormal approximation and using the trigamma function.
The delta method can be used with for all distributions and link functions, while lognormal approximation and trigamma function are limited to distributions with logarithmic link. Trigamma-estimate is recommended whenever available. Additionally, for binomial distributions, theoretical variances exist specific for each link function distribution.
Null model. Calculation of the observation-level variance involves in
some cases fitting a null model containing no fixed effects other than
intercept, otherwise identical to the original model (including all the random
effects). When using r.squaredGLMM
for several models differing only in
their fixed effects, in order to avoid redundant calculations, the null model
object can be passed as the argument null
.
Otherwise, a null model will be fitted via updating the original model.
This assumes that all the variables used in the original model call have the
same values as when the model was fitted. The function warns about this when
fitting the null model is required. This warnings can be disabled by setting
options(MuMIn.noUpdateWarning = TRUE)
.
Important: as of MuMIn version 1.41.0,
r.squaredGLMM
returns a revised statistics based on Nakagawa et
al. (2017) paper. The returned value's format also has changed (it is a
matrix
rather than a numeric vector as before). Pre-1.41.0 version of the
function calculated the “theoretical” GLMM for binomial
models.
GLMM can be calculated also for fixed-effect models. In
the simpliest case of OLS it reduces to var(fitted) /
(var(fitted) + deviance / 2)
. Unlike likelihood-ratio based for
OLS, value of this statistic differs from that of
the classical .
Currently methods exist for classes: merMod
, lme
,
glmmTMB
, glmmADMB
, glmmPQL
, cpglm
(m
) and
(g
)lm
.
For families other than gaussian, Gamma, poisson, binomial and negative binomial,
the residual variance is obtained using get_variance
from package insight.
See note in r.squaredLR
help page for comment on using in
model selection.
Nakagawa, S., Schielzeth, H. 2013 A general and simple method for obtaining from Generalized Linear Mixed-effects Models. Methods in Ecology and Evolution 4, 133–142.
Johnson, P. C. D. 2014 Extension of Nakagawa & Schielzeth’s GLMM to random slopes models. Methods in Ecology and Evolution 5, 44–946.
Nakagawa, S., Johnson, P. C. D., Schielzeth, H. 2017 The coefficient of determination and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded. J. R. Soc. Interface 14, 20170213.
r2
from package performance calculates
GLMM also for variance at different levels, with optional confidence
intervals. r2glmm has functions for and partial .