Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

r.squaredGLMM

Pseudo-R-squared for Generalized Mixed-Effect models


Description

Calculate conditional and marginal coefficient of determination for Generalized mixed-effect models (R_GLMM²).

Usage

r.squaredGLMM(object, null, ...)
## S3 method for class 'merMod'
r.squaredGLMM(object, null, envir = parent.frame(), pj2014 = FALSE, ...)

Arguments

object

a fitted linear model object.

null

optionally, a null model, including only random effects. See ‘Details’.

envir

optionally, the environment in which the null model is to be evaluated. Defaults to the current frame. See eval.

pj2014

logical, if TRUE and object is of poisson family, the result will include R_GLMM² using original formulation of Johnson (2014). This requires fitting object with an observation-level random effect term added.

...

additional arguments, ignored.

Details

For mixed-effects models, R_GLMM² comes in two types: marginal and conditional.

Marginal R_GLMM² represents the variance explained by the fixed effects, and is defined as:

R_GLMM(m)² = (σ_f²) / (σ_f² + σ_α² + σ_ε²)

Conditional R_GLMM² is interpreted as a variance explained by the entire model, including both fixed and random effects, and is calculated according to the equation:

R_GLMM(c)² = (σ_f² + σ_α²) / (σ_f² + σ_α² + σ_ε²)

where σ_f² is the variance of the fixed effect components, σ_α² is the variance of the random effects, and σ_ε² is the “observation-level” variance.

Three different methods are available for deriving the observation-level variance σ_\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).

Value

r.squaredGLMM returns a two-column numeric matrix, each (possibly named) row holding values for marginal and conditional R_GLMM² calculated with different methods, such as “delta”, “log-normal”, “trigamma”, or “theoretical” for models of binomial family.

Note

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” R_GLMM² for binomial models.

R_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 R² for OLS, value of this statistic differs from that of the classical R².

Currently methods exist for classes: merMod, lme, glmmTMB, glmmADMB, glmmPQL, cpglm(m) and (g)lm.

See note in r.squaredLR help page for comment on using R² in model selection.

Author(s)

Kamil Bartoń. This implementation is based on R code from ‘Supporting Information’ for Nakagawa et al. (2014), (the extension for random-slopes) Johnson (2014), and includes developments from Nakagawa et al. (2017).

References

Nakagawa, S., Schielzeth, H. (2013) A general and simple method for obtaining R² from Generalized Linear Mixed-effects Models. Methods in Ecology and Evolution 4: 133–142

Johnson, P.C.D. (2014) Extension of Nakagawa & Schielzeth’s R_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 R² and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded. J. R. Soc. Interface 14: 20170213.

See Also

Examples

data(Orthodont, package = "nlme")

fm1 <- lme(distance ~ Sex * age, ~ 1 | Subject, data = Orthodont)

fmnull <- lme(distance ~ 1, ~ 1 | Subject, data = Orthodont)

r.squaredGLMM(fm1)
r.squaredGLMM(fm1, fmnull)
r.squaredGLMM(update(fm1, . ~ Sex), fmnull)

r.squaredLR(fm1)
r.squaredLR(fm1, null.RE = TRUE)
r.squaredLR(fm1, fmnull) # same result

## Not run: 
if(require(MASS)) {
    fm <- glmmPQL(y ~ trt + I(week > 2), random = ~ 1 | ID, 
        family = binomial, data = bacteria, verbose = FALSE)
    fmnull <- update(fm, . ~ 1)
    r.squaredGLMM(fm)

    # Include R2GLMM (delta method estimates) in a model selection table:
    # Note the use of a common null model
    dredge(fm, extra = list(R2 = function(x) r.squaredGLMM(x, fmnull)["delta", ]))
    
}

## End(Not run)

MuMIn

Multi-Model Inference

v1.43.17
GPL-2
Authors
Kamil Bartoń
Initial release
2020-04-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.