Re: [R] RESIDUALS IN THE AR TIME SERIES FUNCTION

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon 04 Jul 2005 - 18:43:44 EST

On 7/4/05, Talarico Massimiliano (Xelion) <Massimiliano.Talarico@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)

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 04 18:47:47 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:11 EST