rsquared: R-squared for linear regression

Description Usage Arguments Details Value Author(s) References Examples

View source: R/rsquared.R

Description

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

Usage

1
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)

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:

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

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

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.

Author(s)

Jon Lefcheck <lefcheckj@si.edu>

References

Nakagawa, Shinichi, Paul CD Johnson, and Holger Schielzeth. "The coefficient of determination R 2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded." Journal of the Royal Society Interface 14.134 (2017): 20170213.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  ## 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))
  
## End(Not run)

piecewiseSEM documentation built on Jan. 13, 2021, 6:46 a.m.