All problems
Partial Autocorrelation Lag 1
Problem
Estimate the lag-1 partial autocorrelation as the sample Pearson correlation between the series and itself shifted by one: correlate x[0..n-2] with x[1..n-1], centering each sub-series on its own mean.
Return 0.0 if the series has fewer than three points or either sub-series is constant. For lag 1 this equals the regression-based PACF.
Hint
This is just Pearson correlation between the two overlapping sub-series.
Test cases
case 1
in: [[1,2,3,4]]
expected: 0.9999999999999998
case 2
in: [[1,3,2,4]]
expected: -0.4999999999999999
case 3
in: [[5,5,5,5]]
expected: 0
case 4
in: [[4,2,8,6]]
expected: -0.1428571428571428
Starter codePython
def partial_autocorrelation_lag1(series):
# Your code here
pass4 test cases · run your code against them in the editor