Learn R Programming

lmtest (version 0.9-35)

lrtest: Likelihood Ratio Test of Nested Models

Description

lrtest is a generic function for carrying out likelihood ratio tests. The default method can be employed for comparing nested (generalized) linear models (see details below).

Usage

lrtest(object, …)

# S3 method for default lrtest(object, …, name = NULL)

# S3 method for formula lrtest(object, …, data = list())

Arguments

object

an object. See below for details.

further object specifications passed to methods. See below for details.

name

a function for extracting a suitable name/description from a fitted model object. By default the name is queried by calling formula.

data

a data frame containing the variables in the model.

Value

An object of class "anova" which contains the log-likelihood, degrees of freedom, the difference in degrees of freedom, likelihood ratio Chi-squared statistic and corresponding p value.

Details

lrtest is intended to be a generic function for comparisons of models via asymptotic likelihood ratio tests. The default method consecutively compares the fitted model object object with the models passed in . Instead of passing the fitted model objects in , several other specifications are possible. The updating mechanism is the same as for waldtest: the models in can be specified as integers, characters (both for terms that should be eliminated from the previous model), update formulas or fitted model objects. Except for the last case, the existence of an update method is assumed. See waldtest for details.

Subsequently, an asymptotic likelihood ratio test for each two consecutive models is carried out: Twice the difference in log-likelihoods (as derived by the logLik methods) is compared with a Chi-squared distribution.

The "formula" method fits a lm first and then calls the default method.

See Also

waldtest

Examples

Run this code
# NOT RUN {
## with data from Greene (1993):
## load data and compute lags
data("USDistLag")
usdl <- na.contiguous(cbind(USDistLag, lag(USDistLag, k = -1)))
colnames(usdl) <- c("con", "gnp", "con1", "gnp1")

fm1 <- lm(con ~ gnp + gnp1, data = usdl)
fm2 <- lm(con ~ gnp + con1 + gnp1, data = usdl)

## various equivalent specifications of the LR test
lrtest(fm2, fm1)
lrtest(fm2, 2)
lrtest(fm2, "con1")
lrtest(fm2, . ~ . - con1)
# }

Run the code above in your browser using DataLab