All problems
KPSS Level Statistic Lite
Problem
Compute the KPSS level stationarity statistic. Let S_t be the partial sums of the demeaned series; the statistic is sum(S_t^2) / (n^2 * sample_variance), using the population variance as the long-run variance estimate.
Return 0.0 for fewer than two observations or a constant series.
Hint
Trending series have partial sums that drift far from zero, inflating the statistic.
Test cases
case 1
in: [[1,3,2,4,3,5]]
expected: 0.4166666666666667
case 2
in: [[1,1,1,1]]
expected: 0
case 3
in: [[1]]
expected: 0
case 4
in: [[0,1,0,1,0,1]]
expected: 0.08333333333333333
case 5
in: [[2,4,6,8,10]]
expected: 0.52
Starter codePython
def kpss_level_statistic(series):
# Your code here
pass5 test cases · run your code against them in the editor