All problems
Sample Size with Attrition
Problem
Return the number of participants to enroll so that required_n complete the study when a fraction attrition drop out: ceil(required_n / (1 - attrition)). Return 0 when required_n <= 0 or attrition is outside [0, 1).
Hint
Inflate the required completers by the retention rate.
Test cases
case 1
in: [100,0.2]
expected: 125
case 2
in: [100,0]
expected: 100
case 3
in: [50,0.5]
expected: 100
case 4
in: [10,0.15]
expected: 12
case 5
in: [10,1]
expected: 0
Starter codePython
import math
def sample_size_with_attrition(required_n, attrition):
# Your code here
pass5 test cases · run your code against them in the editor