`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 `list(object, …)`

the function tries to consecutively compute fitted models using the following
updating algorithm:

For each two consecutive objects, `object1`

and `object2`

say, try to turn `object2`

into a fitted model that can be
compared to (the already fitted model object) `object1`

.

If `object2`

is numeric, the corresponding element of
`attr(terms(object1), "term.labels")`

is selected to be omitted.

If `object2`

is a character, the corresponding terms are
included into an update formula like `. ~ . - term2a - term2b`

.

If `object2`

is a formula, then compute the fitted model via
`update(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 model objects. Except for the last case, the existence of an `update`

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 `vcov`

is specified, HC and HAC estimators can also be plugged into `waldtest`

.

The default method is already very general and applicable to a broad range of fitted
model objects, including `lm`

and `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
to `waldtest`

, as mentioned above), `nobs`

(or `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
in `terms`

), `vcov`

(can be user-supplied; needs to be named matching the
names in `terms`

). Furthermore, some means of determining a suitable `name`

for
a fitted model object can be specified (by default this is taken to be the result of
a call to `formula`

, if available).

The `"formula"`

method fits a `lm`

first and then calls the `"lm"`

method. The `"lm"`

method just calls the default method, but sets the default
test to be the F test.