dynlm                 package:dynlm                 R Documentation

_D_y_n_a_m_i_c _L_i_n_e_a_r _M_o_d_e_l_s _a_n_d _T_i_m_e-_S_e_r_i_e_s _R_e_g_r_e_s_s_i_o_n

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

     Interface to 'lm.wfit' for fitting dynamic linear models and
     time-series regression relationships.

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

     dynlm(formula, data, subset, weights, na.action, method = "qr",
       model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE,
       contrasts = NULL, offset, start = NULL, end = NULL, ...)

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

 formula: a '"formula"' describing the linear model to be fit. For
          details see below and 'lm'.

    data: an optional '"data.frame"' or time-series object (e.g.,
          '"ts"' or '"zoo"'), containing the variables in the model. 
          If not found in 'data', the variables are taken from
          'environment(formula)', typically the environment from which
          'lm' is called.

  subset: an optional vector specifying a subset of observations to be
          used in the fitting process.

 weights: an optional vector of weights to be used in the fitting
          process. If specified, weighted least squares is used with
          weights 'weights' (that is, minimizing 'sum(w*e^2)');
          otherwise ordinary least squares is used.

na.action: a function which indicates what should happen when the data
          contain 'NA's.  The default is set by the 'na.action' setting
          of 'options', and is 'na.fail' if that is unset.  The
          "factory-fresh" default is 'na.omit'. Another possible value
          is 'NULL', no action. Note, that for time-series regression
          special methods like 'na.contiguous', 'na.locf' and
          'na.approx' are available.

  method: the method to be used; for fitting, currently only 'method =
          "qr"' is supported; 'method = "model.frame"' returns the
          model frame (the same as with 'model = TRUE', see below).

model, x, y, qr: logicals.  If 'TRUE' the corresponding components of
          the fit (the model frame, the model matrix, the response, the
          QR decomposition) are returned.

singular.ok: logical. If 'FALSE' (the default in S but not in R) a
          singular fit is an error.

contrasts: an optional list. See the 'contrasts.arg' of
          'model.matrix.default'.

  offset: this can be used to specify an _a priori_ known component to
          be included in the linear predictor during fitting.  An
          'offset' term can be included in the formula instead or as
          well, and if both are specified their sum is used.

   start: start of the time period which should be used for fitting the
          model.

     end: end of the time period which should be used for fitting the
          model.

     ...: additional arguments to be passed to the low level regression
          fitting functions.

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

     The interface and internals of 'dynlm' are very similar to 'lm',
     but currently 'dynlm' offers two advantages over the direct use of
     'lm': 1. extended formula processing, 2. preservation of
     time-series attributes.

     For specifying the 'formula' of the model to be fitted, there are
     additional functions available which facilitate the specification
     of  dynamic models. An example would be 'd(y) ~ L(y, 2)', where
     'd(x, k)' is 'diff(x, lag = k)' and 'L(x, k)' is 'lag(x, lag =
     -k)', note the difference in sign. The default for 'k' is in both
     cases '1'.

     The specification of dynamic relationships only makes sense if
     there is an underlying ordering of the observations. Currently,
     'lm' offers only limited support for such data, hence a major aim
     of 'dynlm' is to preserve  time-series properties of the data.
     Explicit support is currently available  for '"ts"' and '"zoo"'
     series. Internally, the data is kept as a '"zoo"' series and
     coerced back to '"ts"' if the original dependent variable was of
     that class (and not internal 'NA's were created by the
     'na.action').

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

     'zoo', 'merge.zoo'

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

     ## multiplicative SARIMA(1,0,0)(1,0,0)_12 model fitted
     ## to UK seatbelt data
     uk <- log10(UKDriverDeaths)
     dfm <- dynlm(uk ~ L(uk, 1) + L(uk, 12))
     dfm
     ## explicitely set start and end
     dfm <- dynlm(uk ~ L(uk, 1) + L(uk, 12), start = c(1975, 1), end = c(1982, 12))
     dfm

     ## remove lag 12
     dfm0 <- update(dfm, . ~ . - L(uk, 12))
     anova(dfm0, dfm)

     ## add season term
     dfm1 <- dynlm(uk ~ 1, start = c(1975, 1), end = c(1982, 12))
     dfm2 <- dynlm(uk ~ season(uk), start = c(1975, 1), end = c(1982, 12))
     anova(dfm1, dfm2)

     plot(uk)
     lines(fitted(dfm0), col = 2)
     lines(fitted(dfm2), col = 4)

     ## Examples 7.11/7.12 from Greene (1993)
     if(require(lmtest)) {
     data(USDistLag)
     dfm1 <- dynlm(consumption ~ gnp + L(consumption), data = USDistLag)
     dfm2 <- dynlm(consumption ~ gnp + L(gnp), data = USDistLag)
     plot(USDistLag[, "consumption"])
     lines(fitted(dfm1), col = 2)
     lines(fitted(dfm2), col = 4)
     encomptest(dfm1, dfm2)
     }

