Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-126

First-Differences Estimator

Problem

Return the first-differences slope sum(dx*dy)/sum(dx^2) over consecutive pairs of a time-ordered series. Return 0.0 when n < 3, lengths differ, or the differenced x values are all zero.

Hint

Differencing removes fixed effects before regressing.

Test cases

case 1
in: [[1,2,3,4],[1,3,5,7]]
expected: 2
case 2
in: [[1,2,3],[2,2,2]]
expected: 0
case 3
in: [[1,3,2,5],[1,5,4,9]]
expected: 1.7142857142857142
case 4
in: [[1,2],[1,2]]
expected: 0
case 5
in: [[1,1,2],[1,2,3]]
expected: 1
Starter codePython
def first_differences_estimator(x, y):
    # Your code here
    pass

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