All problems
Cochran-Armitage Trend
Problem
Return the standardized Cochran-Armitage trend statistic sum(w_i*(x_i - n_i*p))/sqrt(p*(1-p)*(sum(w_i^2*n_i) - (sum(w_i*n_i))^2/N)) for cases, group totals, and numeric dose scores. Return 0.0 for empty or mismatched input, zero totals, an overall proportion at 0 or 1, or zero trend variance.
Hint
The statistic is the dose-weighted covariance of cases and scores, standardized.
Test cases
case 1
in: [[10,20,30],[100,100,100],[0,1,2]]
expected: 3.5355339059327373
case 2
in: [[5,10,15],[50,50,50],[0,1,2]]
expected: 2.5
case 3
in: [[20,20,20],[100,100,100],[0,1,2]]
expected: 0
case 4
in: [[0,0,0],[100,100,100],[0,1,2]]
expected: 0
case 5
in: [[10,20],[100,100],[0,1]]
expected: 1.9802950859533488
Starter codePython
def cochran_armitage(cases, totals, scores):
# Your code here
pass5 test cases · run your code against them in the editor