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:
-
n1
- the number of observations in the first model. -
n2
- the number of observations in the second model. -
ll1
- log-likelihood value of the first model. -
ll2
- log-likelihood value of the second model. -
df1
- the number of parameters in the first model. -
df2
- the number of parameters in the second model. -
restrictions
- the number of restrictions in the nested model. -
value
- chi-squared test statistic value. -
p_value
- p-value of the chi-squared test.
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)