All problems
Posterior After Two Positive Tests
Problem
Posterior probability of disease after two conditionally independent positive tests, given prevalence, sensitivities and specificities:
posterior odds = prior odds * LR1 * LR2 with LR = sensitivity / (1 - specificity).
Return 1.0 when a specificity equals 1, and handle prevalences of 0 and 1 gracefully.
Hint
Multiplying likelihood ratios is the same as applying Bayes' rule twice.
Test cases
case 1
in: [0.01,0.9,0.9,0.9,0.9]
expected: 0.4500000000000001
case 2
in: [0.001,0.99,0.95,0.99,0.95]
expected: 0.28183229813664556
case 3
in: [0.5,0.9,0.9,0.9,0.9]
expected: 0.9878048780487805
case 4
in: [0.01,0.9,1,0.9,0.9]
expected: 1
Starter codePython
def two_test_posterior(prevalence, sens1, spec1, sens2, spec2):
# Your code here
pass4 test cases · run your code against them in the editor