Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-188

Prevalence CI (Logit)

Problem

Return the logit-transformed confidence interval for a prevalence cases/n: compute logit(p) +/- z*sqrt(1/cases + 1/(n-cases)) and map the limits back through the logistic function. Return [0.0, 0.0] when n <= 0 or cases is not strictly between 0 and n.

Hint

The logit interval stays inside (0, 1) and improves coverage near the boundaries.

Test cases

case 1
in: [20,100,1.96]
expected: [0.13281509097654504,0.289812602171032]
case 2
in: [5,50,1.96]
expected: [0.042242109705314265,0.21869770261195032]
case 3
in: [50,100,1.645]
expected: [0.41848395843712505,0.581516041562875]
case 4
in: [0,50,1.96]
expected: [0,0]
case 5
in: [50,50,1.96]
expected: [0,0]
Starter codePython
import math
def prevalence_ci(cases, n, z_crit):
    # Your code here
    pass

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