Returns (pseudo)-R^2 values for all linear, generalized linear, and generalized linear mixed effects models.

rsquared(modelList, method = NULL)

Arguments

modelList

a regression, or a list of structural equations.

method

The method used to compute the R2 value (See Details)

Value

Returns a data.frame with the response, its family and link, the method used to estimate R2, and the R2 value itself. Mixed models also return marginal and conditional R2 values.

Details

For mixed models, marginal R2 considers only the variance by the fixed effects, and the conditional R2 by both the fixed and random effects.

For GLMs (glm), supported methods include:

  • mcfadden 1 - ratio of likelihoods of full vs. null models

  • coxsnell McFadden's R2 but raised to 2/N. Upper limit is < 1

  • nagelkerke Adjusts Cox-Snell R2 so that upper limit = 1. The DEFAULT method

For GLMERs fit to Poisson, Gamma, and negative binomial distributions (glmer, glmmPQL, glmer.nb), supported methods include

  • delta Approximates the observation variance based on second-order Taylor series expansion. Can be used with many families and link functions

  • lognormal Observation variance is the variance of the log-normal distribution

  • trigamma Provides most accurate estimate of the observation variance but is limited to only the log link. The DEFAULT method

For GLMERs fit to the binomial distribution (glmer, glmmPQL), supported methods include:

  • theoretical Assumes observation variance is pi^2/3

  • delta Approximates the observation variance as above. The DEFAULT method

References

Nakagawa, Sinichi, Johnson, Paul C.D., and Holger Schielzeth. "The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisted and expanded." bioRxiv 095851 (2017).

Examples

# NOT RUN { # Create data dat <- data.frame( ynorm = rnorm(100), ypois = rpois(100, 100), x1 = rnorm(100), random = letters[1:5] ) # Get R2 for linear model rsquared(lm(ynorm ~ x1, dat)) # Get R2 for generalized linear model rsquared(glm(ypois ~ x1, "poisson", dat)) rsquared(glm(ypois ~ x1, "poisson", dat), method = "mcfadden") # McFadden R2 # Get R2 for generalized least-squares model rsquared(gls(ynorm ~ x1, dat)) # Get R2 for linear mixed effects model (nlme) rsquared(nlme::lme(ynorm ~ x1, random = ~ 1 | random, dat)) # Get R2 for linear mixed effects model (lme4) rsquared(lme4::lmer(ynorm ~ x1 + (1 | random), dat)) # Get R2 for generalized linear mixed effects model (lme4) rsquared(lme4::glmer(ypois ~ x1 + (1 | random), family = poisson, dat)) rsquared(lme4::glmer(ypois ~ x1 + (1 | random), family = poisson, dat), method = "delta") # Get R2 for generalized linear mixed effects model (glmmPQL) rsquared(MASS::glmmPQL(ypois ~ x1, random = ~ 1 | random, family = poisson, dat)) # }