Skip to content
DeepForgeby svx
All problems
EasyStatisticsst-057

Durbin-Watson Statistic

Problem

Return the Durbin-Watson statistic sum((e_i - e_(i-1))^2) / sum(e_i^2) for a list of residuals. Return 0.0 when fewer than two residuals are given or all residuals are zero.

Hint

Values near 2 indicate no autocorrelation; values near 0 indicate positive autocorrelation.

Test cases

case 1
in: [[1,1,1,1]]
expected: 0
case 2
in: [[1,-1,1,-1]]
expected: 3
case 3
in: [[1,2,1,2]]
expected: 0.3
case 4
in: [[0,0,0]]
expected: 0
case 5
in: [[2]]
expected: 0
Starter codePython
def durbin_watson(residuals):
    # Your code here
    pass

5 test cases · run your code against them in the editor