All problems
RDD Triangular Kernel Weight
Problem
Return the triangular kernel weight max(0, 1 - |x - cutoff|/bandwidth) used by local linear regression discontinuity, evaluated at x. Return 0.0 for non-positive bandwidth or when the point is outside the bandwidth.
Hint
Weight decays linearly to zero at the bandwidth edge.
Test cases
case 1
in: [1.5,1,2]
expected: 0.75
case 2
in: [3,1,2]
expected: 0
case 3
in: [1,1,2]
expected: 1
case 4
in: [1,1,0]
expected: 0
case 5
in: [0,1,2]
expected: 0.5
Starter codePython
def rdd_kernel_weight(x, cutoff, bandwidth):
# Your code here
pass5 test cases · run your code against them in the editor