waldtest               package:lmtest               R Documentation

_W_a_l_d _T_e_s_t _o_f _N_e_s_t_e_d _M_o_d_e_l_s

_D_e_s_c_r_i_p_t_i_o_n:

     '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).

_U_s_a_g_e:

      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"))

_A_r_g_u_m_e_n_t_s:

  object: an object. See below for details.

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

    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 model.

    test: character specifying wether to compute the large sample
          Chi-squared statistic (with asymptotic Chi-squared
          distribution) or the finite sample F statistic (with
          approximate F distribution).

    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.

_D_e_t_a_i_l_s:

     '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: 

        1.  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'.

        2.  If 'object2' is numeric, the corresponding element of
           'attr(terms(object1), "term.labels")' is selected to be
           omitted.

        3.  If 'object2' is a character, the corresponding terms are
           included into an update formula like '. ~ . - term2a -
           term2b'.

        4.  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 deterimining the variables in the model along with
     their names), 'update' (unless only fitted model objects are
     passed to 'waldtest', as mentioned above), 'residuals' (only used
     for determining the number of observations), 'df.residual' (needed
     for the F statisic), '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').

     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.

_V_a_l_u_e:

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

_S_e_e _A_l_s_o:

     'coeftest', 'anova', 'linear.hypothesis'

_E_x_a_m_p_l_e_s:

     ## 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
     ## (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)  

