Learn R Programming

lmtest (version 0.9-12)

waldtest: Wald Test

Description

waldtest is a generic function for carrying out Wald tests. Methods for comparing nested linear models (specified via formulas or fitted "lm" objects) are provided.

Usage

waldtest(object, ...)

## S3 method for class 'formula': waldtest(object, \dots)

## S3 method for class 'lm': waldtest(object, \dots, vcov = NULL, test = c("F", "Chisq"), data = list())

Arguments

object
an object. For the formula and lm method this can either be a symbolic description of a linear model or a fitted object of class "lm".
...
further arguments passed to methods. For the formula and lm method this can be further formulas or models to be compared with object. See below for further details.
test
character specifying wether to compute the finite sample F statistic (with approximate F distribution) or the large sample Chi-squared statistic (with asymptotic Chi-squared distribution).
vcov
a function for estimating the covariance matrix of the regression coefficients, e.g., vcovHC. If only two models are compared it can also be the covariance matrix of the more general mode
data
an optional data frame containing the variables in the model. By default the variables are taken from the environment which waldtest is called from.

Value

  • An object of class "anova" which contains the residual degrees of freedom, the difference in degrees of freedom, Wald statistic (either "F" or "Chisq") and corresponding p value.

Details

waldtest is intended to be a generic function for comparisons of models via Wald tests. Methods for comparing linear models are provided. The methods for objects of classes "formula" and "lm" both compare linear models: waldtest.formula simply calls waldtest.lm passing on all other arguments. waldtest.lm takes all objects in list(object, ...) and tries to compute fitted linear models from them using the following algorithm:
  1. Ifobjectis a formula, fit the corresponding linear model.
  2. For each two consecutive objects,object1andobject2say, try to turnobject2into a fitted model that can be compared toobject1.
  3. Ifobject2is numeric, the corresponding element ofattr(terms(object1), "term.labels")is selected.
  4. Ifobject2is a character, the corresponding terms are included into an update formula like. ~ . - term2a - term2b.
  5. Ifobject2is a formula, then compute the fitted model viaupdate(object1, object2).
Consequently, the models in ... can be specified as integers, characters (both for terms that should be eliminated from the previous model), update formulas or fitted "lm" objects. Subsequently, a Wald test for each two consecutive models is carried out. This is very similar to anova, but with a few differences. If only one "lm" object is specified, it is compared to the trivial model (with only an intercept). The test can be either the finite sample F statistic or the asymptotic Chi-squared statistic ($F = Chisq/k$ if $k$ is the difference in degrees of freedom). The covariance matrix is always estimated on the more general of two subsequent models (and not only in the most general model overall). If vcov is specified, HC and HAC estimators can also be plugged into waldtest.

See Also

coeftest, anova, linear.hypothesis

Examples

Run this code
## fit two competing, non-nested models and their encompassing
## model for aggregate consumption, as in Greene (1993),
## Examples 7.11 and 7.12

## load data and compute lags
data(USDistLag)
usdl <- na.contiguous(cbind(USDistLag, lag(USDistLag, k = -1)))
colnames(usdl) <- c("con", "gnp", "con1", "gnp1")

## C(t) = a0 + a1*Y(t) + a2*C(t-1) + u
fm1 <- lm(con ~ gnp + con1, data = usdl)

## C(t) = b0 + b1*Y(t) + b2*Y(t-1) + v
fm2 <- lm(con ~ gnp + gnp1, data = usdl)

## Encompassing model
fm3 <- lm(con ~ gnp + con1 + gnp1, data = usdl)

## a simple ANOVA for fm3 vs. fm1
waldtest(fm3, fm2)
anova(fm3, fm2)
## as df = 1, the test is equivalent to the corresponding t test in
coeftest(fm3)

## various equivalent specifications of the two models
waldtest(fm3, fm2)
waldtest(fm3, 2)
waldtest(fm3, "con1")
waldtest(fm3, . ~ . - con1)

## comparing more than one model
## (euqivalent to the encompassing test)
waldtest(fm1, fm3, fm2)
encomptest(fm1, fm2)

## using the asymptotic Chisq statistic
waldtest(fm3, fm2, test = "Chisq")
## plugging in a HC estimator
if(require(sandwich)) waldtest(fm3, fm2, vcov = vcovHC)

Run the code above in your browser using DataLab