[R] RESIDUALS IN THE AR TIME SERIES FUNCTION
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Jul 4 10:43:44 CEST 2005
On 7/4/05, Talarico Massimiliano (Xelion)
<Massimiliano.Talarico at xelion.unicredit.it> wrote:
> Dear all,
>
> It's possible to obtain the residuals with AR time series function.
There is no residuals method for the "ar" class but you could
try this using the lh dataset as an example. Note that the
zoo package is required in order to use zoo's lag function,
which has been enhanced to take a vector of lags, and dyn
of the dyn package is used to add dynamic regression
capabilities to lm. Also, this example uses features in
the most recent versions of the dyn and zoo packages
so be sure you have the latest ones from CRAN.
ar(lh)
library(dyn) # this also brings in zoo
lh.zoo <- as.zoo(lh)
lh.lm <- dyn$lm(lh.zoo ~ lag(lh.zoo, -seq(3)))
lh.lm # seems close to the coefficients calculated by ar
resid(lh.lm)
More information about the R-help
mailing list