nagelR2: Nagelkerge's / Craig & Uhler's R2

nagelR2R Documentation

Nagelkerge's / Craig & Uhler's R2

Description

Nagelkerge's / Craig & Uhler's R2

Usage

nagelR2(likeNull, likeFull, n)

Arguments

likeNull

Likelihood (not log-likelihood) of the null model or an object of class logLik with log-likelihood of the null model (usually an intercept-only model).

likeFull

Likelihood (not log-likelihood) of the "full" model or an object of class logLik with log-likelihood of the "full" model (usually a model with covariates).

n

Sample size.

Value

Numeric.

Examples


# create data
x <- 1:100
y <- 2 + 1.7 * x + rnorm(100, 0, 30)

# models
nullModel <- lm(y ~ 1)
fullModel <- lm(y ~ x)

# plot
plot(x, y)
abline(nullModel, col='red')
abline(fullModel, col='blue')
legend('bottomright', legend=c('Null', 'Full'), lwd=1, col=c('red', 'blue'))

# R2
likeNull <- exp(as.numeric(logLik(nullModel)))
likeFull <- exp(as.numeric(logLik(fullModel)))
nagelR2(likeNull, likeFull, 100)

adamlilith/statisfactory documentation built on Jan. 3, 2024, 10:37 p.m.