Compute sample size and Bayes posterior
RobloxData Scientist · Online AssessmentLast updated
This question evaluates understanding of statistical inference and probabilistic reasoning by combining a frequentist power/sample-size computation for a two-sided two-sample z-test with a basic Bayesian conditional probability calculation.
You are implementing two small statistical utilities.
Part A — Power / sample size (two-sample z-test)
- Input:
x: a 1D numeric array of historical observations of a metric (assume i.i.d.).alpha: significance level (e.g., 0.05).power: desired power (e.g., 0.8).effect_size: the minimum detectable absolute difference in means, Δ (same units asx).- Task: Compute the required per-group sample size
nfor an equal-sized A/B test using a two-sided two-sample z-test. - Assumptions:
- The metric variance is the same in both groups.
- Population standard deviation is unknown; estimate it from
xusing the sample standard deviations. - Independent samples, normal approximation.
- Output: return the smallest integer
nthat achieves the requested power (round up).
Part B — Bayes’ rule
- Input: probabilities
p_A = P(A),p_B_given_A = P(B|A),p_B_given_notA = P(B|¬A). - Task: compute and return
P(A|B). - Assumptions:
0 < p_A < 1and all conditional probabilities are valid.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.