All problems
Durbin-Watson
Problem
Compute the Durbin-Watson statistic: sum((e_t - e_{t-1})^2) / sum(e_t^2).
Return 0.0 with fewer than two residuals or a zero denominator.
Hint
Values near 2 indicate no autocorrelation; near 0 suggests positive autocorrelation.
Test cases
case 1
in: [[1,-1,1,-1]]
expected: 3
case 2
in: [[1,2,3]]
expected: 0.14285714285714285
case 3
in: [[0,0,0]]
expected: 0
case 4
in: [[2,1,2,1]]
expected: 0.3
Starter codePython
def durbin_watson(residuals):
# Your code here
pass4 test cases · run your code against them in the editor