【AI 核心深度 M1-043】样本量与功效的关系是什么?写出常用的样本量估算思路。(Explain the Mathematical Relationship Between Sample Size and Statistical Power with Sizing Formulas)深度数理推导与工程落地解析

所属模块:M1 · 数学与统计基础 (Mathematics & Statistics Fundamentals) | 专题分类:假设检验 (Hypothesis Testing) | 难度等级:Medium

一、核心一句话结论 (One-Sentence Summary)

样本量与效应量平方成反比;功效分析反解所需 n。

ADVERTISEMENT · 赞助推荐

Sample size scales inversely with the square of Minimum Detectable Effect ($N propto 1/delta^2$); halving the effect size requires quadrupling the sample size.

二、核心考点要义 (Key Insights)

  • 📌 A/B 上线前必做功效分析,避免’欠功效实验’
  • 📌 方差可用历史数据或 CUPED 降低

English Insights:
– Standard sample size formula: $N = frac{2(z_{1-alpha/2} + z_{1-beta})^2 sigma^2}{delta^2}$ for two-sample equal-allocation tests.
– Square-root law: Standard error shrinks at rate $O(1/sqrt{N})$, compelling exponential sample requirements for tiny metrics.
– Key inputs: Significance level $alpha$ (typically 0.05), Power $1-beta$ (typically 0.80), Baseline variance $sigma^2$, and MDE $delta$.

三、核心数学原理与机理推导 (Mathematical Principles & Derivation)

$$n propto frac{(z_{1-alpha/2}+z_{1-beta})^2,sigma^2}{Delta^2}$$

推导(两样本均值比较):检验统计量 Z=(X̄A−X̄B)/√(2σ²/n),在 H₀ 下 ~N(0,1),在 H₁(真实差异 Δ)下 ~N(Δ/√(2σ²/n), 1)。拒绝域为 |Z|>z)²/Δ²。核心结论:n 与效应量 Δ 的平方成反比——效应减半,样本量需增至 4 倍;n 与方差 σ² 成正比(方差翻倍,样本量翻倍)。这两个关系决定了实验设计的基本约束:小效应实验极其昂贵。},要求 H₁ 下落入拒绝域的概率 ≥ 1−β,即 (Δ/√(2σ²/n)) − z{1−α/2} ≥ z_{1−β},解出 n ≥ 2σ²(z_{1−α/2}+z_{1−β

📖 查看英文严格数学推导 (English Mathematical Derivation)

For two-sample z-test with $N$ users per variant, the difference in sample means $Delta = bar{X}_B – bar{X}_A$ has variance $text{Var}(Delta) = frac{sigma_A^2}{N} + frac{sigma_B^2}{N} approx frac{2sigma^2}{N}$. Under $H_0$, critical threshold is $C = z_{1-alpha/2} sqrt{frac{2sigma^2}{N}}$. Under $H_1: Delta = delta$, statistical power requires $P(Delta > C mid H_1) = 1 – beta$, which means $C = delta – z_{1-beta} sqrt{frac{2sigma^2}{N}}$. Equating the two expressions for $C$: $z_{1-alpha/2} sqrt{frac{2sigma^2}{N}} = delta – z_{1-beta} sqrt{frac{2sigma^2}{N}} implies (z_{1-alpha/2} + z_{1-beta}) sqrt{frac{2sigma^2}{N}} = delta$. Squaring and solving for $N$: $N = frac{2(z_{1-alpha/2} + z_{1-beta})^2 sigma^2}{delta^2}$. For $alpha=0.05, 1-beta=0.80$, $(1.96 + 0.84)^2 = 7.84$, giving rule-of-thumb $N approx frac{16sigma^2}{delta^2}$.

四、工业级落地权衡与工程考量 (Industrial Trade-offs)

实践要点:① MDE 必须先定——MDE(最小可检测效应)应由业务价值决定(如’至少提升 0.5% 转化率才值得上线’),而非由样本量倒推;反过来做(先定样本量再问能检出什么)会导致’实验能检出什么就上什么’的荒谬决策。② 降方差等于免费加样本——由 n∝σ²,方差降低 50% 等价于样本量翻倍;CUPED 用实验前协变量常能降低 30–50% 方差,是工业界最高杠杆的优化。③ 分流比例的影响——若处理组只占 p 比例,有效样本量下降,最优通常是 50/50(方差在等分时最小),但当处理有风险或成本高时可用不均衡分流。④ 指标类型不同公式不同——比率型指标(CTR)用 p(1−p) 代替 σ²,计数型需考虑过度离散,重尾指标应改用 bootstrap 或稳健估计。

⚙️ 查看英文落地权衡分析 (English Systems & Trade-offs)

If traffic is constrained and MDE cannot be achieved within acceptable timeframes, applied scientists have three options: (1) Variance reduction (CUPED): Reduces effective $sigma^2$ by factor $(1-rho^2)$, cutting required $N$ by up to 50%. (2) Transform metrics: Switch from noisy continuous revenue to conversion rate or binarized flags with lower coefficient of variation. (3) Multi-week run durations to capture weekly seasonality.

五、常见面试避坑陷阱 (Common Pitfalls & Traps)

  • ⚠️ 先定样本量再倒推能检出什么(应由业务价值定 MDE)
  • ⚠️ 忽视方差降低(CUPED)对样本量的等效替代作用

English Pitfalls:
– Setting MDE based on wishful thinking rather than business ROI thresholds.
– Ignoring clustering in sample size calculations when randomization unit differs from analysis unit (e.g. User-level treatment with page-level metrics).

六、高频深度面试追问与预测 (Follow-Up Questions)

  1. 最小可检测效应(MDE)怎么定?
  2. How does sample size calculation change for binary proportion metrics ($p(1-p)$ variance)?
  3. 为什么要先定 MDE 再算样本量?
  4. Why must sample size be inflated by the Design Effect (DEFF) in cluster-randomized experiments?

七、知识图谱对齐 (Knowledge Graph Anchor)

  • 🔗 关联底层卡片:数理统计假说检验、P 值、I/II 类错误与统计功效 (Hypothesis Testing, P-Values, Power & Type I/II Error)
  • 🗺️ 知识图谱模块:数理基础思维导图

🔬 算法科学家与机器学习深度考察全量题库 (Science Depth)

本题收录于 TalentMe 算法科学家深度考察真题库 (Science Depth)。全库共 856 道硬核考点,深度覆盖数学统计、经典ML、深度学习、Transformer、大语言模型、多模态、推荐系统与 MLOps。支持 Jev 面经智能匹配、一键离线单文件 HTML 手册导出并直连 Obsidian 本地记忆。

👉 前往 TalentMe 交互式研读本题 (M1-043) →


Discover more from AirSOTA – Air School Of Thoughts AtoZ

Subscribe to get the latest posts sent to your email.