def durbin_watson(resids, axis=0):
 resids = np.asarray(resids)
 diff_resids = np.diff(resids, 1, axis=axis)
 dw = (np.sum((diff_resids ** 2), axis=axis) / np.sum((resids ** 2), axis=axis))
 return dw

def durbin_watson ( resids , axis = 0 ) : resids = np . asarray ( resids ) diff_resids = np . diff ( resids , 1 , axis = axis ) dw = ( np . sum ( ( diff_resids ** 2 ) , axis = axis ) / np . sum ( ( resids ** 2 ) , axis = axis ) ) return dw
calculates the durbin-watson statistic parameters resids : array-like returns dw : float .