Re: [R] Testing autocorrelation & heteroskedasticity of residuals in ts

From: Achim Zeileis <Achim.Zeileis_at_wu-wien.ac.at>
Date: Wed 21 Jul 2004 - 19:32:58 EST

On Wed, 21 Jul 2004 10:28:41 +0200 Pfaff, Bernhard wrote:

> >
> > Hi,
> >
> > I'm dealing with time series. I usually use stl() to
> > estimate trend, stagionality and residuals. I test for
> > normality of residuals using shapiro.test(), but I
> > can't test for autocorrelation and heteroskedasticity.
> > Is there a way to perform Durbin-Watson test and
> > Breusch-Pagan test (or other simalar tests) for time
> > series?
> > I find dwtest() and bptest() in the package lmtest,
>
> Hello Vito,
>
> how about:
>
> library(lmtest)
> data(nottem)
> test <- summary(stl(nottem, s.win=4))
> bptest(formula(nottem ~ -1 + test$time.series[,1] +
> test$time.series[,2])) dwtest(formula(nottem ~ -1 +
> test$time.series[,1] + test$time.series[,2]))
>
> i.e. you define the residuals by providing the residuals as formula.
> Note:
> testres <- nottem-test$time.series[,1]-test$time.series[,2]
> cbind(testres, test$time.series[,3])

Further note that testres are not the residuals that you supply to dwtest() above because the coefficients are

R> coef(lm(formula(nottem ~ -1 + test$time.series[,1] +

        test$time.series[,2])))
test$time.series[, 1] test$time.series[, 2]

            0.9988047 1.0002117

but they are close to 1.

Anyway: for dwtest() I would probably just supply the residuals and regress them on a constant.

R> dwtest(test$time.series[,3] ~ 1)

which is very close to Bernhard's suggestion but a bit simpler.

For bptest() you could do something like

bptest(test$time.series[,3] ~ 1 ,

       varformula = ~ -1 + test$time.series[,1] + test$time.series[,2])

if that is the model you would like to test. At least it makes more explicit what is tested.

> Anyway, are these tests applicable to stl as far as the underlying
> assumptions for the error term is concerned?

I don't know any formal results about this but it should not be difficult to find a set of assumptions where a nonparametric estimate of trend and season via STL yields a stationary, independent and homoskedastic sequence of the residuals. (whether these apply to Vito's data is of course a different question :))

Best,
Achim  

> Bernhard
>
>
> > but it requieres an lm object, while I've a ts object.
> > Any help will be appreciated.
> > Best
> > Vito
> >
> > =====
> > Diventare costruttori di soluzioni
> >
> > Visitate il portale http://www.modugno.it/
> > e in particolare la sezione su Palese
> http://www.modugno.it/archivio/cat_palese.shtml
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
> ---------------------------------------------------------------------
> ----------- The information contained herein is confidential and is
> inte...{{dropped}}
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jul 21 19:38:58 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:09 EST