Fit Autoregressive Models to Time Series by OLS

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

ar.ols(x, aic = TRUE, order.max = NULL, na.action =,
       demean = TRUE, intercept = demean, series, ...)
A univariate or multivariate time series.
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.
Maximum order (or order) of model to fit. Defaults to $10\log_{10}(N)$ where $N$ is the number of observations.
function to be called to handle missing values.
should the AR model be for x minus its mean?
should a separate intercept term be fitted?
names for the series. Defaults to deparse(substitute(x)).
further arguments to be passed to or from methods.

ar.ols fits the general AR model 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. For definiteness, note that the AR coefficients have the sign in

$$x_t - \mu = a_0 + a_1(x_{t-1} - \mu) + \cdots + a_p(x_{t-p} - \mu) + e_t$$

where $a_0$ is zero unless intercept is true, and $\mu$ is the sample mean if demean is true, zero otherwise.

Order selection is done by AIC if aic is true. This is problematic, as ar.ols does not perform true maximum likelihood estimation. The AIC is computed as if the variance estimate (computed from the variance matrix of the residuals) 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.

Some care is needed if intercept is true and demean is false. Only use this is the series are roughly centred on zero. Otherwise the computations may be inaccurate or fail entirely.


  • A list of class "ar" with the following elements:
  • orderThe order of the fitted model. This is chosen by minimizing the AIC if aic = TRUE, otherwise it is order.max.
  • arEstimated autoregression coefficients for the fitted model.
  • var.predThe prediction variance: an estimate of the portion of the variance of the time series that is not explained by the autoregressive model.
  • x.meanThe estimated mean (or zero if demean is false) of the series used in fitting and for use in prediction.
  • x.interceptThe intercept in the model for x - x.mean, or zero if intercept is false.
  • aicThe differences in AIC between each model and the best-fitting model. Note that the latter can have an AIC of -Inf.
  • n.usedThe number of observations in the time series.
  • order.maxThe value of the order.max argument.
  • partialacfNULL. For compatibility with ar.
  • residresiduals 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.
  • methodThe character string "Unconstrained LS".
  • seriesThe name(s) of the time series.
  • frequencyThe frequency of the time series.
  • callThe matched call.
  • asymptotic-theory standard errors of the coefficient estimates.


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

See Also


  • ar.ols
library(stats) ar(lh, method = "burg") ar.ols(lh) ar.ols(lh, FALSE, 4) # fit ar(4) ar.ols(ts.union(BJsales, BJsales.lead)) x <- diff(log(EuStockMarkets)) ar.ols(x, order.max = 6, demean = FALSE, intercept = TRUE)
Documentation reproduced from package stats, version 3.3, License: Part of R 3.3

Community examples

Looks like there are no examples yet.