Hi,
I ran an experiment with 3 factors, 2 levels and 200 replications and as I want to test for residuals independence, I used Durbin-Watson in R. I found two functions (durbin.watson and dwtest) and while both are giving the same rho, the p-values are greatly differ: > durbin.watson(mod1) lag Autocorrelation D-W Statistic p-value 1 -0.04431012 2.088610 0.012 Alternative hypothesis: rho != 0 > dwtest(mod1) Durbin-Watson test data: mod1 DW = 2.0886, p-value = 0.9964 alternative hypothesis: true autocorrelation is greater than 0 durbin.watson suggests that I should reject the null hypothesis while dwtest suggests that I should NOT reject Ho. If I look it up in the following table: http://www.stanford.edu/~clint/bench/dw05d.htm, T = 1600 and K = 8 gives dL = 1.90902 and dU = 1.92659. Which means I should not reject Ho as DW > dU. Is there a bug in durbin.watson? should I use dwtest instead? can somebody help me explain what is happening? Thank you, ~ Hardi ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
On Wed, 5 Aug 2009, Hardi wrote:
> Hi, > > I ran an experiment with 3 factors, 2 levels and 200 replications and as > I want to test for residuals independence, I used Durbin-Watson in R. > I found two functions (durbin.watson and dwtest) and while both are > giving the same rho, the p-values are greatly differ: > >> durbin.watson(mod1) > lag Autocorrelation D-W Statistic p-value > 1 -0.04431012 2.088610 0.012 > Alternative hypothesis: rho != 0 > >> dwtest(mod1) > Durbin-Watson test > data: mod1 > DW = 2.0886, p-value = 0.9964 > alternative hypothesis: true autocorrelation is greater than 0 > > durbin.watson suggests that I should reject the null hypothesis while > dwtest suggests that I should NOT reject Ho. What do you expect? The default alternative in durbin.watson() is rho != 0 (as displayed above!) and in dwtest() it is rho > 0 (as displayed above!). For an empirical correlation of -0.044 one would hope that the p-values are very different. Beyond that, the approaches for computing the p-value in durbin.watson() and dwtest() are different. The former uses resampling techniques, the latter uses either the exact or approximate asymptotic distribution. > If I look it up in the following table: > http://www.stanford.edu/~clint/bench/dw05d.htm, T = 1600 and K = 8 gives > dL = 1.90902 and dU = 1.92659. > Which means I should not reject Ho as DW > dU. First, this is inferior technology compared to both approaches discussed above. Second, you are using it wrong! These are upper and lower bounds for a single critical value for the one-sided alternative rho > 0. So interpreting it correctly DW > dU means that you can confidently conclude that DW is _not_ significant. But you didn't need a significance test for that when the empirical correlation is less than zero and you want to show that it is greater than zero. > Is there a bug in durbin.watson? should I use dwtest instead? can > somebody help me explain what is happening? It might help if you read about the theory behind the Durbin-Watson test and why it is difficult to evaluate its null distributions. Best, Z ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
In reply to this post by Hardi-4
Thank you for all your reply, especially Alan
Now I understand better how does the durbin watson test works. But this means that my residuals are not independent (note that I'm doing this test to validate the ANOVA assumption that the residuals are independent). The results were taken from a simulation result and each run are supposed to be independent to each other and I am grouping the data based on design points. The plot from residuals vs fitted and residuals vs time looks random enough although each groups has slightly different variance. Am I heading the correct way here, by testing the independence of the whole residuals (which resulting the failure of independence test) or should I test for the independence for each groups? (which resulting the passing of the test). Thank you very much, ~ Hardi ----- Original Message ---- From: Alan Cohen <[hidden email]> To: [hidden email] Sent: Thursday, August 6, 2009 9:38:19 PM Subject: Durbin-Watson Hi Hardi, I saw the first reply you got to your question, which was correct but snippy and a bit over-technical. To say it more clearly (and nicely - appreciating that you will not become a statistical guru of every test you ever use), you have performed a two-tailed test with durbin.watson() and a one-tailed test with dwtest(), so the p-value for the former should be approximately twice that for the latter. Your one-tailed test was performed in the wrong direction - your autocorrelation is negative, but you were testing for a positive association. 1-p = 1-0.9964 = 0.0036. This is still not exactly the same as 0.018/2=0.0059, but the ranges are similar, and if you need to figure it out in more depth I'd refer back to the first response, which points out the differences in calculation methods. If you want to control the direction of the test in dwtest, use the "alternative" option, copied from the ?dwtest help file below: dwtest(formula, order.by = NULL, alternative = c("greater", "two.sided", "less"), iterations = 15, exact = NULL, tol = 1e-10, data = list()) alternative - a character string specifying the alternative hypothesis. Cheers, Alan Cohen ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
On Fri, 7 Aug 2009, Hardi wrote:
> Now I understand better how does the durbin watson test works. But this > means that my residuals are not independent (note that I'm doing this > test to validate the ANOVA assumption that the residuals are > independent). Yes. The autocorrelation is rather low, though, so it might be hard to see in visualizations that you mention below. > The results were taken from a simulation result and each run are > supposed to be independent to each other and I am grouping the data > based on design points. The plot from residuals vs fitted and residuals > vs time looks random enough although each groups has slightly different > variance. I'm not sure that the Durbin-Watson test is appropriate at all for your data. This seems to be longitudinal or panel data, right? The standard Durbin-Watson test is for time series regressions. (Snippiness alert: This might have become more clear if a textbook would have been consulted more thoroughly as suggested in my previous mail...even though other respondents seem to feel that you do not need to understand the test, or read its manual, to apply it.) > Am I heading the correct way here, by testing the independence of the > whole residuals (which resulting the failure of independence test) or > should I test for the independence for each groups? (which resulting the > passing of the test). Hard to say from your description, but it seems that one of the following might help: using some sandwich covariances (see package "sandwich") after a linear regression with lm() or using GEE (see package "geepack") with a suitable dependence structure. hth, Z ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Free forum by Nabble | Edit this page |