layout: doc-page title: Durbin-Watson Test
The Durbin Watson Test is a test for serial correlation in error terms. The Durbin Watson test statistic (d) can take values between 0 and 4, and in general
Implementation is based off of the durbinWatsonTest
function in the car
package in R
library(car) residuals <- seq(0, 4.9, 0.1) ## perform Durbin-Watson test durbinWatsonTest(residuals)
// A DurbinWatson Test must be performed on a model. The model does not matter. val drmX = drmParallelize( dense((0 until 50).toArray.map( t => Math.pow(-1.0, t)) ) ).t val drmY = drmX + err1 + 1 var model = new OrdinaryLeastSquares[Int]().fit(drmX, drmY) // end arbitrary model val err1 = drmParallelize( dense((0.0 until 5.0 by 0.1).toArray) ).t val syntheticResiduals = err1 model = AutocorrelationTests.DurbinWatson(model, syntheticResiduals) val myAnswer: Double = model.testResults.getOrElse('durbinWatsonTestStatistic, -1.0).asInstanceOf[Double]