Library
Experiments and causal inference
Read an A/B test correctly, size one, shrink its variance, and get a causal answer when randomization is messy or missing.
A/B testing
When randomization is messy
Practice questions
25Reading an A/B test on conversion
- 1.Your function returns p = 0.0062 for 200/2,000 against 250/2,000, and the practice test expects 0.0124. Two identical groups give p = 0.5. What's wrong?
- 2.At alpha = 0.05 your interval for the worked example is (0.0086, 0.0414). The reference gives (0.0054, 0.0446). How often does yours cover the true difference?
- 3.Why does the z statistic use the pooled rate while the interval uses each group's own rate?
- 4.Your z uses the unpooled standard error, so it's 2.5039 on the worked example instead of 2.5020. When does that bug actually hurt?
- 5.A PM checks a 14-day test every day and stops it the first time p < 0.05. If the treatment does nothing, about how often does the test end on a significant result?
Sample size for a test
- 1.You compute the alpha z as NormalDist().inv_cdf(1 - alpha). What happens to the 10% to 12% test?
- 2.A teammate sizes a test of 2% to 3% with 2 * 0.02 * 0.98 as the variance. What goes wrong?
- 3.The PM wants to detect a 2% lift on a 10% conversion rate and means 2% of the baseline. How many users per arm is that, against 3,839 for 2 points?
- 4.The formula gives 3,838.10 users per arm. What should the function return?
- 5.A test sized for a 2-point lift, 3,839 users per arm on a 10% baseline, runs on a change whose true lift is 1 point. When it comes out significant, what lift does it report on average?
CUPED variance reduction
- 1.The pre-period metric has a correlation of 0.8 with the test-period metric. With CUPED, about what share of the original sample size does the test need for the same power?
- 2.On the practice data your adjusted metric comes out with 2.65 times the raw variance, while its mean and θ are both right. What did you write?
- 3.In a simulation, x is each user's sessions over the two weeks before the test and y their sessions in the test's one week, so var(x) is about 3 times var(y). You compute theta as
cov(x, y) / var(y). What happens? - 4.You compute
theta = np.cov(x, y)[0, 1] / np.var(x)on the practice data's 1,000 users. Which test fails, and why? - 5.Your function returns
y - theta * x, with no centering, and you call it once on both arms. Which number is still right?
Randomized by city, analyzed by user
- 1.Cities of 1,000 users each, randomized by city, and the ICC is only 0.01. How far off is the naive standard error?
- 2.On the practice data with city effects, you swap the naive standard error for a heteroskedasticity-robust one. What happens?
- 3.With 40 cities and 2,000 users, what does the factor G/(G - 1) × (N - 1)/(N - K) do to the clustered standard error?
- 4.Your naive_se divides the residual sum of squares by N instead of N - K. Why is N - K right?
- 5.Six cities of equal size, three of them treated. Which test keeps its false positive rate at 5%?
Difference-in-differences
- 1.Treated cities averaged 53.75 before launch and 63.5 after. Control cities averaged 41.75 and 47.5. What is the difference-in-differences estimate?
- 2.Your
pre_trend_gapfits each group's slope on all 16 weeks of a practice panel. The trends are parallel and the effect is 2, starting at week 8. About what does it return? - 3.Treated cities trend 0.3 a week faster than control cities, before and after launch. The pre weeks are 0 to 7, the post weeks 8 to 15, and the true effect is 2. What does difference-in-differences return on average?
- 4.Thirty cities, 16 weeks, a placebo launch with no real effect, and weekly shocks that carry over from one week to the next. You fit two-way fixed effects and use the plain OLS standard error. About how often is the placebo significant at 5%?
- 5.Two waves of cities launch in week 4 and week 10, every city ends up treated, and the effect grows each week after launch. Why can one two-way fixed effects regression return a negative number?