Pattern in the Leftovers
The points (x[i], y[i]) are in time order. Fit an ordinary least squares line and return the Durbin-Watson statistic of its residuals: about 2 when neighbors in time are unrelated, toward 0 when each residual resembles the one before it, toward 4 when they alternate.
Example 1
x [1,2,3,4,5,6]
y [1,3,2,4,3,5]
returns 3.547619047619047
The residuals flip sign at every step, which pushes the statistic toward 4.
Constraints
5 <= len(x) <= 60- The points are not exactly on a line
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More statsmodels problems
- Point That Pulls HardestMedium
- Tangled PredictorsMedium
- Top of the CurveMedium
- Trust Some Points MoreMedium
- Uneven SpreadMedium
- Do the Effects CombineHard
- Drop the Weak OnesHard
- Effect of the ProgramHard