ar(x, aic=T, order.max=<<see below>>, method="yule-walker")
TRUE, use the Akaike information criterion to choose the
best order not greater than
order.max.
If
FALSE,
order.max will be the order of the fitted model.
10 * log10(n.used/ncol(x)).
"yule-walker"
or
"burg" depending on whether Yule-Walker equations
or Burg's algorithm is to be used in estimating the autoregression coefficients.
Only the first character is necessary.
aic=TRUE, then this is the order less than or equal to
order.max
which minimizes the AIC, otherwise, it is
order.max.
order by "nser"
by "nser" array. where "nser" is the number of univariate components
of
x. If
order is
0,
ar will have dimensions
1 by "nser" by "nser"
and will be filled with zeros.
The first level of the first dimension corresponds to one observation back in
time, the second level corresponds to two observations back, etc.
The second dimension corresponds to the predicted series, and the third
corresponds to the predicting series.
ar.
0 through
order.max.
These have the minimum value subtracted from all of them so the minimum
is always zero.
order.max.
method="yule-walker".
ar are used in the forward direction on the
series with mean(s) removed.
"yule-walker" or
"burg".
x.
It includes transformations.
If
method="yule-walker", the autocovariance matrices of the time
series are estimated and
Whittle's recursion (a multivariate extension of the Levinson-Durbin method)
is used to estimate the autoregressive coefficients.
The coefficients can also be estimated by using Burg's
algorithm, based on the principle of maximum entropy.
The output may be used in
spec.ar to estimate the spectrum of the process,
or
acf.plot to produce a plot of the partial autocorrelation function.
The estimation is performed using the sample mean of each univariate
series as the estimate of the mean.
Remember that the coefficients in
ar are for the series with the mean(s)
removed.
The chapter "Analyzing Time Series" of the S-PLUS Guide to Statistical and Mathematical Analysis.
a <- ar(log(lynx))
acf.plot(a, conf=T) # Take a look at the partial correlations
tsplot(a$aic)
# Fit an AR(11) to this time series
lynx.fit <- ar(log(lynx), aic=F, order=11, method="b")
# function to predict using an ar model:
# ahead gives the number of predictions to make
pred.ar <- function(series, ar.est, ahead = 1)
{
order <- ar.est$order
series <- as.matrix(series)
pred.out <- array(NA, dim = c(order + ahead, ncol(series)), dimnames =
list(NULL, dimnames(series)[[2]]))
mean.ser <- apply(series, 2, mean)
ser.cent <- sweep(series, 2, mean.ser)
pred.out[seq(order), ] <- ser.cent[rev(nrow(series) - seq(order) +
1), ]
for(i in (order + 1):nrow(pred.out)) {
pred.out[i, ] <- apply(aperm(ar.est$ar, c(1, 3, 2)) *
as.vector(pred.out[i - seq(order), ]), 3, sum)
}
sweep(pred.out[ - seq(order), , drop = F], 2, mean.ser, "+")
}
sun.ar <- ar(sunspots)
tsplot(sun.ar$resid, main="Residuals from AR(27) Fit of Sunspots")
# the structure in the residuals means the model is inadequate