Free Access Week - Data Engineering + BI
Data Engineering and BI courses are free this week!
Free Access Week - Jun 2-8

sjmisc (version 1.6)

r2: Compute R-squared of (generalized) linear (mixed) models

Description

Compute R-squared values of linear (mixed) models, or pseudo-R-squared values for generalized linear (mixed) models.

Usage

r2(x)

Arguments

x
Fitted model of class lm, glm, lmerMod/lme or glmerMod.

Value

    • For linear models, the r-squared and adjusted r-squared values.
    • For linear mixed models, the r-squared and Omega-squared values.
    • Forglmobjects, Cox & Snell's and Nagelkerke's pseudo r-squared values.
    • ForglmerModobjects, Tjur's coefficient of determination.

References

  • http://glmm.wikidot.com/faq{DRAFT r-sig-mixed-models FAQ}
  • Byrnes, J. 2008. Re: Coefficient of determination (R^2) when using lme().http://thread.gmane.org/gmane.comp.lang.r.lme4.devel/684{gmane.comp.lang.r.lme4.devel}
  • Xu, R. 2003. Measuring explained variation in linear mixed effects models. Statist. Med. 22:3527-3541.10.1002/sim.1572
  • Tjur T. 2009. Coefficients of determination in logistic regression models - a new proposal: The coefficient of discrimination. The American Statistician, 63(4): 366-372

Examples

Run this code
library(lme4)
fit <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
r2(fit)

data(efc)
fit <- lm(barthtot ~ c160age + c12hour, data = efc)
r2(fit)

# Pseudo-R-squared values
efc$services <- dicho(efc$tot_sc_e, "v", 0, as.num = TRUE)
fit <- glm(services ~ neg_c_7 + c161sex + e42dep,
           data = efc,
           family = binomial(link = "logit"))
r2(fit)

Run the code above in your browser using DataLab