All problems
QQ Plot Slope and Intercept
Problem
Fit a line through the points (theoretical quantile, sample quantile) using population moments and return [slope, intercept], where slope = cov(q, s)/var(q) and intercept = mean(s) - slope*mean(q). Return [0.0, 0.0] when fewer than two points are given or the theoretical quantiles are constant.
Hint
It is ordinary least squares on the quantile pairs.
Test cases
case 1
in: [[-1,0,1],[2,4,6]]
expected: [2,4]
case 2
in: [[0,1,2],[1,3,5]]
expected: [2,1]
case 3
in: [[1,2,3],[3,3,3]]
expected: [0,3]
case 4
in: [[5,5],[1,2]]
expected: [0,0]
case 5
in: [[1],[1]]
expected: [0,0]
Starter codePython
def qq_slope_intercept(theoretical, sample):
# Your code here
pass5 test cases · run your code against them in the editor