Learn R Programming

spatialreg.hp (version 0.0-1)

nagelkerke_r2_lm: Calculate Nagelkerke pseudo R-squared for a linear model

Description

This function computes the Nagelkerke pseudo R-squared for a linear model (`lm` object) by comparing the log-likelihood of the fitted model to that of the null model (intercept-only).

Usage

nagelkerke_r2_lm(model)

Value

A numeric value representing the Nagelkerke pseudo R-squared.

Arguments

model

An object of class lm.

Details

Nagelkerke R² is a normalized version of the likelihood ratio R², scaled to have a maximum of 1. It is commonly used for generalized linear models but can also be applied to linear models.

The formula used is: $$R^2_{Nagelkerke} = \frac{1 - \exp\left(\frac{2}{n} (LL_{null} - LL_{model})\right)}{1 - \exp\left(\frac{2}{n} LL_{null}\right)}$$ where \(LL_{model}\) is the log-likelihood of the fitted model and \(LL_{null}\) is the log-likelihood of the null model.

References

Nagelkerke, N. J. D. (1991). A note on a general definition of the coefficient of determination. Biometrika, 78(3), 691–692.

Examples

Run this code
data(mtcars)
fit <- lm(mpg ~ wt + hp, data = mtcars)
nagelkerke_r2_lm(fit)

Run the code above in your browser using DataLab