Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-171

Base-Rate Fallacy False Positive Share

Problem

For a disease with prevalence prevalence and a test with the given sensitivity and specificity, return the fraction of positive tests that are false positives:

share = (1 - prevalence) * (1 - specificity) / (prevalence * sensitivity + (1 - prevalence) * (1 - specificity)).

Return 0.0 when the denominator is 0 or inputs are invalid.

Hint

Even a good test produces many false positives when the disease is rare.

Test cases

case 1
in: [0.01,0.99,0.99]
expected: 0.5000000000000002
case 2
in: [0.001,0.99,0.99]
expected: 0.9098360655737706
case 3
in: [0.5,0.9,0.9]
expected: 0.09999999999999998
Starter codePython
def false_positive_share(prevalence, sensitivity, specificity):
    # Your code here
    pass

3 test cases · run your code against them in the editor