Skip to content
Prev 72942 / 398500 Next

RESIDUALS IN THE AR TIME SERIES FUNCTION

On 7/4/05, Talarico Massimiliano (Xelion)
<Massimiliano.Talarico at xelion.unicredit.it> wrote:
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)