Learn R Programming

rcompanion (version 1.0.1)

nagelkerke: Pseudo r-squared measures for various models

Description

Produces McFadden, Cox and Snell, and Nagelkerke pseudo R-squared measures, along with p-values, for models.

Usage

nagelkerke(fit, null = NULL)

Arguments

fit
The fitted model object for which to determine pseudo r-squared.
null
The null model object against which to compare the fitted model object. The null model must be nested in the fitted model to be valid. This is optional for some model objects and required for others.

Value

A list of four objects describing the models used, the pseudo r-squared values, the likelihood ratio test for the model, and any warning messages.

Details

Pseudo R-squared values are not directly comparable to the R-squared for OLS models. Nor can they be interpreted as the proportion of the variability in the dependent variable that is explained by model. Instead pseudo R-squared measures are relative measures among similar models indicating how well the model explains the data. Cox and Snell is also referred to as ML. Nagelkerke is also referred to as Cragg and Uhler. Model objects accepted are lm, glm, gls, lme, lmer, lmerTest, nls, clm, clmm, vglm, glmer, negbin, zeroinfl. Model objects that require the null model to be defined are nls, lmer, glmer and clmm. Other objects use the update function to define the null model. Likelihoods are found using ML (REML = FALSE).

References

http://rcompanion.org/handbook/G_10.html

See Also

nagelkerkeHermite

Examples

Run this code
### Logistic regression example
data(AndersonBias)
model = glm(Result ~ County + Sex + County:Sex,
           weight = Count,
           data = AndersonBias,
           family = binomial(link="logit"))
nagelkerke(model)

### Quadratic plateau example 
### With nls, the  null needs to be defined
data(BrendonSmall)
quadplat = function(x, a, b, clx) {
          ifelse(x  < clx, a + b * x   + (-0.5*b/clx) * x   * x,
                           a + b * clx + (-0.5*b/clx) * clx * clx)}
model = nls(Sodium ~ quadplat(Calories, a, b, clx),
            data = BrendonSmall,
            start = list(a   = 519,
                         b   = 0.359,
                         clx = 2304))
nullfunct = function(x, m){m}
null.model = nls(Sodium ~ nullfunct(Calories, m),
             data = BrendonSmall,
             start = list(m   = 1346))
nagelkerke(model, null=null.model)

Run the code above in your browser using DataLab