ar                    package:ts                    R Documentation

_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

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

_U_s_a_g_e:

     ar(x, aic = TRUE, order.max = NULL,
        method=c("yule-walker", "burg", "ols", "mle", "yw"), na.action,
        series, ...)

     ar.burg(x, ...)
     ## Default S3 method:
     ar.burg(x, aic = TRUE, order.max = NULL,
             na.action = na.fail, demean = TRUE, series, var.method = 1, ...)
     ## S3 method for class 'mts':
     ar.burg(x, aic = TRUE, order.max = NULL,
             na.action = na.fail, demean = TRUE, series, var.method = 1, ...)

     ar.yw(x, ...)
     ## Default S3 method:
     ar.yw(x, aic = TRUE, order.max = NULL,
           na.action = na.fail, demean = TRUE, series, ...)
     ## S3 method for class 'mts':
     ar.yw(x, aic = TRUE, order.max = NULL,
           na.action = na.fail, demean = TRUE, series, ...)

     ar.mle(x, aic = TRUE, order.max = NULL, na.action = na.fail, demean = TRUE,
            series, ...)

     ## S3 method for class 'ar':
     predict(object, 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 Information
          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 sufficient).  Defaults to '"yule-walker"'.

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

  demean: should a mean be estimated during fitting?

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

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

     ...: additional arguments for specific methods.

  object: 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_t_a_i_l_s:

     For definiteness, note that the AR coefficients have the sign in


 '(x[t] - m) = a[1]*(x[t-1] - m) + ... +  a[p]*(x[t-p] - m) + e[t]'


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

     'ar.burg' allows two methods to estimate the innovations 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. In the multivariate case the estimated coefficients
     will depend (slightly) on the variance estimation method.

     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.mle') estimating a constant to subtract.

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

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

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

x.intercept: ('ar.ols' only.) The intercept in the model for 'x -
          x.mean'.

     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 case.) The asymptotic-theory variance matrix
          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 case of 'ar.mle' is 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 univariate case of 'ar.burg' by B. D. Ripley.

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

     Percival, D. P. and Walden, A. T. (1998) _Spectral Analysis for
     Physical Applications._ Cambridge University Press.

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

_S_e_e _A_l_s_o:

     'ar.ols', 'arima0' for ARMA models.

_E_x_a_m_p_l_e_s:

     data(lh)
     ar(lh)
     ar(lh, method="burg")
     ar(lh, method="ols")
     ar(lh, FALSE, 4) # fit ar(4)

     data(sunspot)
     (sunspot.ar <- ar(sunspot.year))
     predict(sunspot.ar, n.ahead=25)
     ## try the other methods too

     data(BJsales)
     ar(ts.union(BJsales, BJsales.lead))
     ## Burg is quite different here, as is OLS (see ar.ols)
     ar(ts.union(BJsales, BJsales.lead), method="burg")

