adjR2.glm: Adjusted R-squared in Generalized Linear Models

View source: R/glms.R

adjR2.glmR Documentation

Adjusted R-squared in Generalized Linear Models

Description

Computes the adjusted deviance-based R-squared in generalized linear models.

Usage

## S3 method for class 'glm'
adjR2(..., digits = max(3, getOption("digits") - 2), verbose = TRUE)

Arguments

...

one or several objects of the class glm, which are obtained from the fit of generalized linear models.

digits

an (optional) integer value indicating the number of decimal places to be used. As default, digits is set to max(3, getOption("digits") - 2).

verbose

an (optional) logical indicating if should the report of results be printed. As default, verbose is set to TRUE.

Details

The deviance-based R-squared is computed as R^2=1 - Deviance/Null.Deviance. Then, the adjusted deviance-based R-squared is computed as 1 - \frac{n-1}{n-p}(1-R^2), where p is the number of parameters in the linear predictor and n is the sample size.

Value

a matrix with the following columns

Deviance value of the residual deviance,
R-squared value of the deviance-based R-squared,
df number of parameters in the linear predictor,
adj.R-squared value of the adjusted deviance-based R-squared,

Examples

###### Example 1: Fuel efficiency of cars
Auto <- ISLR::Auto
fit1 <- glm(mpg ~ horsepower*weight, family=Gamma(inverse), data=Auto)
fit2 <- update(fit1, formula=mpg ~ horsepower*weight*cylinders)
fit3 <- update(fit1, family=Gamma(log))
fit4 <- update(fit2, family=Gamma(log))
fit5 <- update(fit1, family=inverse.gaussian(log))
fit6 <- update(fit2, family=inverse.gaussian(log))

AIC(fit1,fit2,fit3,fit4,fit5,fit6)
BIC(fit1,fit2,fit3,fit4,fit5,fit6)
adjR2(fit1,fit2,fit3,fit4,fit5,fit6)


glmtoolbox documentation built on Sept. 11, 2024, 7:32 p.m.