

_F_i_t _A_u_t_o_r_e_g_r_e_s_s_i_v_e _M_o_d_e_l_s _t_o _T_i_m_e _S_e_r_i_e_s

     ar(x, aic = TRUE, order.max = NULL,
        method=c("yule-walker", "burg", "ols", "mle"), na.action, series)
     ar.burg(x, aic = TRUE, order.max = NULL, na.action, demean = TRUE, series,
             var.method = 1)
     ar.yw(x, aic = TRUE, order.max = NULL, na.action, demean = TRUE, series)
     ar.ols(x, aic = TRUE, order.max = NULL, na.action, demean = TRUE, series)
     ar.mle(x, aic = TRUE, order.max = NULL, na.action, demean = TRUE, series)
     predict(ar.obj, newdata, n.ahead = 1, se.fit = TRUE)

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

       x: A univariate or multivariate time series.

     aic: Logical flag.  If `TRUE' then the Akaike Informa-
          tion Criterion is used to choose the order of the
          autoregressive model. If `FALSE', the model of
          order `order.max' is fitted.

order.max: Maximum order (or order) of model to fit.
          Defaults to 10*log10(N) where N is the number of
          observations except for `method="mle"' where it is
          the minimum of this quantity and 12.

  method: Character string giving the method used to fit the
          model.  Must be one of the strings in the default
          argument (the first few characters are suffi-
          cient).  Defaults to `"yule-walker"'.

na.action: function to be called to handle missing values.

  demean: should mean be removed before fitting?

  series: name for the series.  Defaults to
          `deparse(substitute(x))'.

var.method: the method to estimate the innovations variance
          (see Details).

  ar.obj: a fit from `ar'.

 newdata: data to which to apply the prediction.

 n.ahead: number of steps ahead at which to predict.

  se.fit: logical: return estimated standard errors of the
          prediction error?

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

     Fit an autoregressive time series model to the data, by
     default selecting the complexity by AIC.

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

     `ar' is just a wrapper for the functions `ar.yw',
     `ar.burg', `ar.ols' and `ar.mle'.

     Order selection is done by AIC if `aic' is true. This
     is problematic, as of the methods here only `ar.mle'
     performs true maximum likelihood estimation. The AIC is
     computed as if the variance estimate were the MLE,
     omitting the determinant term from the likelihood. Note
     that this is not the same as the Gaussian likelihood
     evaluated at the estimated parameter values. In `ar.yw'
     the variance matrix of the innovations is computed from
     the fitted coefficients and the autocovariance of `x'
     and in `ar.ols' from the variance matrix of the residu-
     als.

     `ar.burg' allows two methods to estimate the innova-
     tions variance and hence AIC. Method 1 is to use the
     update given by the Levinson-Durbin recursion
     (Brockwell and Davis, 1991, (8.2.6) on page 242), and
     follows S-PLUS. Method 2 is the mean of the sum of
     squares of the forward and backward prediction errors
     (as in Brockwell and Davis, 1996, page 145). Percival
     and Walden (1998) discuss both.

     Remember that `ar' includes by default a constant in
     the model, by removing the overall mean of `x' before
     fitting the AR model, or (`ar.ols') estimating an addi-
     tive constant.

     `ar.ols' fits the general AR model (containing an
     intercept if `demean = TRUE') to a possibly non-
     stationary and/or multivariate system of series `x'.
     The resulting unconstrained least squares estimates are
     consistent, even if some of the series are non-
     stationary and/or co-integrated.

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

     For `ar' and its methods a list of class `"ar"' with
     the following elements:

   order: The order of the fitted model.  This is chosen by
          minimizing the AIC if `aic=TRUE', otherwise it is
          `order.max'.

      ar: Estimated autoregression coefficients for the fit-
          ted model.

var.pred: The prediction variance: an estimate of the por-
          tion of the variance of the time series that is
          not explained by the autoregressive model.

  x.mean: The estimated mean of the series use in fitting
          and for use in prediction.

     aic: The value of the `aic' argument.

  n.used: The number of observations in the time series.

order.max: The value of the `order.max' argument.

partialacf: The estimate of the partial autocorrelation
          function up to lag `order.max'.

   resid: residuals from the fitted model, conditioning on
          the first `order' observations. The first `order'
          residuals are set to `NA'. If `x' is a time
          series, so is `resid'.

  method: The value of the `method' argument.

  series: The name(s) of the time series.

asy.var.coef: (univariate, not `ar.ols') The asymptotic-
          theory variance matrix of the coefficient esti-
          mates.

asy.se.coef: (`ar.ols' only.) The asymptotic-theory standard
          errors of the coefficient estimates.

          For `predict.ar', a time series of predictions, or
          if `se.fit = TRUE', a list with components `pred',
          the predictions, and `se', the estimated standard
          errors. Both components are time series.

_N_o_t_e:

     Only the univariate cases of `ar.burg' and `ar.mle' are
     implemented.

     Fitting by `method="mle"' to long series can be very
     slow.

_A_u_t_h_o_r(_s):

     Martyn Plummer, univariate case of `ar.yw', `ar.mle'
     and C code for `ar.burg' by B.D. Ripley, `ar.ols' by
     Adrian Trapletti.

_R_e_f_e_r_e_n_c_e_s:

     Brockwell, P. J. and Davis, R. A. (1991) Time Series
     and Forecasting Methods.  Second edition. Springer, New
     York. Section 11.4.

     Brockwell, P. J. and Davis, R. A. (1996) Introduction
     to Time Series and Forecasting. Springer, New York.
     Sections 5.1 and 7.6.

     Luetkepohl, H. (1991): Introduction to Multiple Time
     Series Analysis. Springer Verlag, NY, pp. 368-370.

     Percival, D. P. and Walden, A. T. (1998) Spectral
     Analysis for Physical Applications. Cambridge Univer-
     sity Press.

     Whittle, P. (1963) On the fitting of multivariate
     autoregressions and the approximate canonical factori-
     zation of a spectral density matrix. Biometrika 40,
     129-134.

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

     data(lh)
     ar(lh)
     ar(lh, method="burg")
     ar(lh, method="ols")

     data(LakeHuron)
     ar(LakeHuron)
     ar(LakeHuron, method="burg")
     ar(LakeHuron, method="ols")

     data(sunspot)
     sunspot.ar <- ar(sunspot.year)
     sunspot.ar
     ar(x = sunspot.year, method = "burg")
     ar(x = sunspot.year, method = "ols")
     ## next is slow and may have convergence problems,
     ## as it cares about invertibility
     ar(x = sunspot.year, method = "mle")

     predict(sunspot.ar, n.ahead=25)

     data(BJsales)
     ar(ts.union(BJsales, BJsales.lead))

     data(EuStockMarkets)
     x <- diff(log(EuStockMarkets))
     ar.ols(x, order.max=6)

