Katkat

Compute sample size and Bayes posterior

RobloxData Scientist · Online Assessment

Last 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 as x).
  • Task: Compute the required per-group sample size n for 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 x using the sample standard deviation s.
  • Independent samples, normal approximation.
  • Output: return the smallest integer n that 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 < 1 and all conditional probabilities are valid.