lrtest {switchSelection}R Documentation

Likelihood ratio test

Description

This function performs chi-squared test for nested models.

Usage

lrtest(model1, model2)

Arguments

model1

the first model.

model2

the second model.

Details

Arguments model1 and model2 should be objects of class that has implementations of logLik and nobs methods. It is assumed that either model1 is nested into model2 or vice versa. More precisely it is assumed that the model with smaller log-likelihood value is nested into the model with greater log-likelihood value.

Value

The function returns an object of class 'lrtest' that is a list with the following elements:

Examples

set.seed(123)
# Generate data according to linear regression
n <- 100
eps <- rnorm(n)
x1 <- runif(n)
x2 <- runif(n)
y <- x1 + 0.2 * x2 + eps
# Estimate full model
model1 <- lm(y ~ x1 + x2)
# Estimate restricted (nested) model
model2 <- lm(y ~ x1)
# Likelihood ratio test results
lrtest(model1, model2)

[Package switchSelection version 1.1.2 Index]