Vito Ricci
2004-Jul-21 07:34 UTC
[R] Testing autocorrelation & heteroskedasticity of residuals in ts
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, 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
Pfaff, Bernhard
2004-Jul-21 08:28 UTC
[R] Testing autocorrelation & heteroskedasticity of residuals in ts
> > 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]) Anyway, are these tests applicable to stl as far as the underlying assumptions for the error term is concerned? 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 Palesehttp://www.modugno.it/archivio/cat_palese.shtml ______________________________________________ R-help at 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}}
Wayne Jones
2004-Jul-21 08:41 UTC
[R] Testing autocorrelation & heteroskedasticity of residuals in ts
Hi Vito, I would treat the residuals as a time series. You can fit an arima model to the residuals. For example: data(nottem) temp<-stl(nottem, "per") my.arima<-arima(temp$time.series[,3], order=c(1,0,0), include.mean = FALSE) my.arima tsdiag(my.arima) If the ar1 term is significant then the residuals are auto-correlated. The DW statistic is just another test for this. The command tsdiag gives diagnostic plots for the arima model fit. In terms of heteroskedasticity, the Bruce-Pagan test from package lmtest tests for variance changing as a function of another variable. I think (although I am less sure) you can still use the test. To test whether your variance of residuals is monotonically increasing (or maybe decreasing) over time I would use: library(lmtest) Y<- as.numeric(temp$time.series[,3]) X<-1:nrow(temp$time.series) bptest(Y~X) Regards Wayne -----Original Message----- From: Vito Ricci [mailto:vito_ricci@yahoo.com] Sent: 21 July 2004 08:35 To: r-help@stat.math.ethz.ch Subject: [R] Testing autocorrelation & heteroskedasticity of residuals in ts 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, 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 KSS Ltd Seventh Floor St James's Buildings 79 Oxford Street Manchester M1 6SS England Company Registration Number 2800886 Tel: +44 (0) 161 228 0040 Fax: +44 (0) 161 236 6305 mailto:kssg@kssg.com http://www.kssg.com The information in this Internet email is confidential and m...{{dropped}}