All problems
Robust Standard Error Ratio
Problem
Return the ratio of the HC1 robust standard error of a simple regression slope to the classical one: sqrt(n * sum(xc_i^2 e_i^2) / (Sxx * SSE)), where xc = x - mean(x). Return 0.0 when n < 3, the lengths differ, or Sxx or SSE is zero.
Hint
The ratio equals 1 under homoscedasticity and departs from 1 when error variance tracks x.
Test cases
case 1
in: [[1,2,3,4],[1,-1,1,-1]]
expected: 1
case 2
in: [[1,2,3,4,5],[1,1,1,1,1]]
expected: 1
case 3
in: [[1,2,3,4,5],[1,2,3,4,5]]
expected: 1.0617310051386497
case 4
in: [[1,1,1,1],[1,2,3,4]]
expected: 0
case 5
in: [[1,2,3],[0,0,0]]
expected: 0
Starter codePython
def robust_se_ratio(x, residuals):
# Your code here
pass5 test cases · run your code against them in the editor