NagelkerkeScaledR2: Return the scaled R2 defined by Nagelkerke (1991)

View source: R/NagelkerkeScaledR2.R

NagelkerkeScaledR2R Documentation

Return the scaled R2 defined by Nagelkerke (1991)

Description

Return the scaled R2 of a binomial model based on:
Nagelkerke NJD (1991) A note on a general definition of the coefficient of determination. Biometrika 78:691-192.
This definition of scaled R2 by Nagelkerke (1991) has the following properties:
(i) It is consistent with classical R2, that is the general definition applied to e.g. linear regression yields the classical R2.
(ii) It is consistent with maximum likelihood as an estimation method, i.e. the maximum likelihood estimates of the model parameters maximize R2.
(iii) It is asymptotically independent of the sample size n.
(iv) 1-R2 has the interpretation of the proportion of unexplained 'variation'.
(v) It is dimensionless, i.e. it does not depend on the units used.
The reported value is similar to the value estimated with nagelkerke() function from rcompanion package but not from the NagelkerkeR2() function from fmsb package. I don't know why.

Usage

NagelkerkeScaledR2(x, size, prediction, scaled = TRUE)

Arguments

x

The number of observations

size

Number of trials

prediction

Prediction of x/size

scaled

If TRUE, return the scaled R2

Details

NagelkerkeScaledR2 returns the scaled R2 defined by Nagelkerke (1991)

Value

The scaled R2 value

Author(s)

Marc Girondot marc.girondot@gmail.com

Examples

x <- c(10, 9, 6, 4, 3, 1, 0)
size <- c(10, 10, 10, 10, 10, 10, 10)
prediction <- c(0.9, 0.8, 0.7, 0.5, 0.4, 0.3, 0.2)
NagelkerkeScaledR2(x, size, prediction)

# Using the example in fmsb::NagelkerkeR2
res <- glm(cbind(ncases,ncontrols) ~ agegp+alcgp+tobgp, data=esoph, family=binomial())
NagelkerkeScaledR2(x=esoph$ncases, size = esoph$ncases+esoph$ncontrols, 
                   prediction = res$fitted.values)

HelpersMG documentation built on Sept. 12, 2024, 9:35 a.m.