Learn R Programming

rsq (version 1.1)

rsq.v: Variance-Function-Based R-Squared

Description

Calculate the variance-function-based R-squared for generalized linear models.

Usage

rsq.v(fitObj,adj=FALSE,data=NULL)

Arguments

fitObj

an object of class "lm" or "glm", usually, a result of a call to lm, glm, or glm.nb.

adj

logical; if TRUE, calculate the adjusted R^2.

data

an optional data frame used by fitObj.

Value

The R^2 or adjusted R^2.

Details

The R^2 relies on the variance function, and is well-defined for quasi models. It reduces to the classical R^2 when the variance function is constant or linear.

References

Zhang, D. (2016). A coefficient of determination for generalized linear models. The American Statistician, accepted. <http://dx.doi.org/10.1080/00031305.2016.1256839>.

See Also

rsq, rsq.partial, pcor.

Examples

Run this code
# NOT RUN {
data(hcrabs)
attach(hcrabs)
y <- ifelse(num.satellites>0,1,0)
bnfit <- glm(y~color+spine+width+weight,family=binomial)
rsq.v(bnfit)
rsq.v(bnfit,adj=TRUE)

quasibn <- glm(y~color+spine+width+weight,family=quasibinomial)
rsq.v(quasibn)
rsq.v(quasibn,adj=TRUE)

psfit <- glm(num.satellites~color+spine+width+weight,family=poisson)
rsq.v(psfit)
rsq.v(psfit,adj=TRUE)

quasips <- glm(num.satellites~color+spine+width+weight,family=quasipoisson)
rsq.v(quasips)
rsq.v(quasips,adj=TRUE)

# Effectiveness of Bycycle Safety Helmets in Thompson et al. (1989)
y <- matrix(c(17,218,233,758),2,2)
x <- factor(c("yes","no"))
tbn <- glm(y~x,family=binomial)
rsq.v(tbn)
rsq.v(tbn,adj=TRUE)
# }

Run the code above in your browser using DataLab