rsq {rsq} | R Documentation |
R-Squared for Generalized Linear (Mixed) Models
Description
Calculate the coefficient of determination, aka R^2, for both linear and generalized linear (mixed) models.
Usage
rsq(fitObj,adj=FALSE,type=c('v','kl','sse','lr','n'))
Arguments
fitObj |
an object of class "lm", "glm", "merMod", "lmerMod", or "lme"; usually a result of a call to lm, glm, glm.nb, lmer or glmer or glmer.nb in lme4, or lme in nlme. |
adj |
logical; if TRUE, calculate the adjusted R^2. |
type |
the type of R-squared (only applicable for generalized linear models): 'v' (default) – variance-function-based (Zhang, 2017), calling rsq.v; 'kl' – KL-divergence-based (Cameron and Windmeijer, 1997), calling rsq.kl; 'sse' – SSE-based (Efron, 1978), calling rsq.sse; 'lr' – likelihood-ratio-based (Maddala, 1983; Cox and Snell, 1989; Magee, 1990), calling rsq.lr; 'n' – corrected version of 'lr' (Nagelkerke, 1991), calling rsq.n. |
Details
Calculate the R-squared for (generalized) linear models. For (generalized) linear mixed models, there are three types of R^2 calculated on the basis of observed response values, estimates of fixed effects, and variance components, i.e., model-based R_M^2 (proportion of variation explained by the model in total, including both fixed-effects and random-efffects factors), fixed-effects R_F^2 (proportion of variation explained by the fixed-effects factors), and random-effects R_R^2 (proportion of variation explained by the random-effects factors).
Value
The R^2 or adjusted R^2. For (generalized) linear mixed models,
R_M^2 |
proportion of variation explained by the model in total, including both fixed-effects and random-efffects factors. |
R_F^2 |
proportion of variation explained by the fixed-effects factors. |
R_R^2 |
proportion of variation explained by the random-effects factors. |
Author(s)
Dabao Zhang, Department of Statistics, Purdue University
References
Cameron, A. C. and Windmeijer, A. G. (1997) An R-squared measure of goodness of fit for some common nonlinear regression models. Journal of Econometrics, 77: 329-342.
Cox, D. R. and Snell, E. J. (1989) The Analysis of Binary Data, 2nd ed. London: Chapman and Hall.
Efron, B. (1978) Regression and ANOVA with zero-one data: measures of residual variation. Journal of the American Statistical Association, 73: 113-121.
Maddala, G. S. (1983) Limited-Dependent and Qualitative Variables in Econometrics. Cambridge University.
Magee, L. (1990) R^2 measures based on Wald and likelihood ratio joint significance tests. The American Statistician, 44: 250-253.
Nagelkerke, N. J. D. (1991) A note on a general definition of the coefficient of determination. Biometrika, 78: 691-692.
Zhang, D. (2017). A coefficient of determination for generalized linear models. The American Statistician, 71(4): 310-316.
Zhang, D. (2020). Coefficients of determination for generalized linear mixed models. Technical Report, 20-01, Department of Statistics, Purdue University.
See Also
Examples
data(hcrabs)
attach(hcrabs)
y <- ifelse(num.satellites>0,1,0)
bnfit <- glm(y~color+spine+width+weight,family=binomial)
rsq(bnfit)
rsq(bnfit,adj=TRUE)
quasibn <- glm(y~color+spine+width+weight,family=quasibinomial)
rsq(quasibn)
rsq(quasibn,adj=TRUE)
psfit <- glm(num.satellites~color+spine+width+weight,family=poisson)
rsq(psfit)
rsq(psfit,adj=TRUE)
quasips <- glm(num.satellites~color+spine+width+weight,family=quasipoisson)
rsq(quasips)
rsq(quasips,adj=TRUE)
# Linear mixed models
require(lme4)
lmm1 <- lmer(Reaction~Days+(Days|Subject),data=sleepstudy)
rsq(lmm1)
rsq.lmm(lmm1)
# Generalized linear mixed models
data(cbpp)
glmm1 <- glmer(cbind(incidence,size-incidence)~period+(1|herd),data=cbpp,family=binomial)
rsq(glmm1)