waldtest is a generic function for carrying out Wald tests.
The default method can be employed for comparing nested (generalized)
linear models (see details below).
waldtest(object, ...) ## Default S3 method: waldtest(object, ..., vcov = NULL, test = c("Chisq", "F"), name = NULL) ## S3 method for class 'formula' waldtest(object, ..., data = list()) ## S3 method for class 'lm' waldtest(object, ..., test = c("F", "Chisq"))
an object. See below for details.
further object specifications passed to methods. See below for details.
a function for estimating the covariance matrix of the regression
character specifying whether to compute the large sample Chi-squared statistic (with asymptotic Chi-squared distribution) or the finite sample F statistic (with approximate F distribution).
a function for extracting a suitable name/description from
a fitted model object. By default the name is queried by calling
a data frame containing the variables in the model.
waldtest is intended to be a generic function for comparisons
of models via Wald 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. For all objects in
the function tries to consecutively compute fitted models using the following
For each two consecutive objects,
say, try to turn
object2 into a fitted model that can be
compared to (the already fitted model object)
object2 is numeric, the corresponding element of
attr(terms(object1), "term.labels") is selected to be omitted.
object2 is a character, the corresponding terms are
included into an update formula like
. ~ . - term2a - term2b.
object2 is a formula, then compute the fitted model via
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 model objects. Except for the last case, the existence of an
method is assumed. See also the examples for an illustration.
Subsequently, a Wald test for each two consecutive models is carried out. This
is similar to
anova (which typically performs likelihood-ratio tests),
but with a few differences. If only one fitted model 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
is specified, HC and HAC estimators can also be plugged into
The default method is already very general and applicable to a broad range of fitted
model objects, including
glm objects. It can be
easily made applicable to other model classes as well by providing suitable methods
to the standard generics
terms (for determining the variables in the model
along with their names),
update (unless only fitted model objects are passed
waldtest, as mentioned above),
residuals, used for determining
the number of observations),
df.residual (needed only for the F statistic),
coef (for extracting the coefficients; needs to be named matching the names
vcov (can be user-supplied; needs to be named matching the
terms). Furthermore, some means of determining a suitable
a fitted model object can be specified (by default this is taken to be the result of
a call to
formula, if available).
"formula" method fits a
lm first and then calls the
"lm" method just calls the default method, but sets the default
test to be the F test.
An object of class
"anova" which contains the residual degrees of freedom,
the difference in degrees of freedom, Wald statistic
"F") and corresponding p value.
## 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. fm2 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 ## (equivalent 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.