Skip to content
DeepForgeby svx
All problems
HardTime Seriests-085

VAR Coefficient Estimate

Problem

Estimate a VAR(1) slope coefficient by ordinary least squares, regressing y_current on x_lag: sum((x - mean_x) * (y - mean_y)) / sum((x - mean_x)^2).

Return 0.0 if the lists are empty, have different lengths, or x_lag is constant.

Hint

This is the lag-one cross coefficient of a bivariate VAR.

Test cases

case 1
in: [[1,2,3,4],[2,4,6,8]]
expected: 2
case 2
in: [[1,2,3,4],[0,1,2,3]]
expected: 1
case 3
in: [[1,1,1],[2,3,4]]
expected: 0
case 4
in: [[0,1,2],[1,1,1]]
expected: 0
Starter codePython
def var1_coefficient_estimate(x_lag, y_current):
    # Your code here
    pass

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