08How many users does the test need? (Python, no SciPy)
08 How many users does the test need? (Python, no SciPy)
A prep site lists a Netflix data science onsite question on designing an ad frequency cap experiment and providing its power calculations (1 source). This is the calculation under that answer, not a leaked question.
Set a 30-minute timer. Read one level at a time, and run only that level's tests until they pass:
pytest problems/08_sample_size -k level1. Earlier levels must keep passing. statistics.NormalDist and
math.ceil are in the standard library.
Level 1. sample_size_per_arm(p_baseline, mde, alpha=0.05, power=0.8, relative=False) returns the users
each arm needs to detect an absolute lift of mde over a baseline conversion rate, with a two-sided test at
alpha 0.05 and 80% power. Use each arm's own variance, at the baseline and at the baseline plus mde, and round
up to a whole user (return an int).
Level 2. Honor alpha and power: any two-sided alpha, any power.
Level 3. With relative=True, mde is a share of the baseline: 0.2 on a 10% baseline is a lift to 12%.
Level 4. Add days_to_run(p_baseline, mde, new_users_per_day, share_in_test=1.0, alpha=0.05, power=0.8, relative=False): how long a 50/50 test runs when a share share_in_test of each day's new users enter it. A
part day counts as a whole day, and the answer is in days, rounded up to whole weeks: 7.005 days runs 14.
Things to get right: where each z comes from (alpha, two-sided, and power), why n scales with 1 / mde^2 (halve the lift, quadruple the users), and which daily count turns users into days. Follow-ups: unequal splits, ratio metrics, clustering, and how variance reduction (problem 09) shrinks n.