Delta Method for Ratio Metric Variance
Background
Ratio metrics (CTR, sessions-per-user, GMV-per-visit) don't have an obvious -test: you can't just test the numerator's mean. The delta method linearises the ratio around the sample means via a first-order Taylor expansion, giving a usable variance estimate. The standard tool in production experimentation platforms for variance on ratio KPIs.
Problem statement
Implement delta_method_variance(numerator, denominator):
Use sample variances and sample covariance (Bessel-corrected).
Input
numerator— 1-Dnp.ndarrayof floats, length .denominator— 1-Dnp.ndarrayof floats, length , same length asnumerator.
Output
Returns a Python float >= 0, the estimated variance of the ratio.
Examples
Example 1 — constant denominator collapses to Var(X) / n
Input: numerator = random N(0, 1), denominator = ones
Output: ≈ Var(X) / n
Example 2 — both noisy → positive variance
Input: both N(10, 2) and N(20, 3)
Output: > 0
Example 3 — length mismatch
Input: shape (3,) and (4,)
Output: ValueError
Constraints
numeratoranddenominatormust have the same length, .- Use Bessel correction for variance and covariance.
- Returns a Python
float.
Notes
- Sensitivity to small . If is near zero, the ratio's variance blows up. Production code adds a "clip " or a guard before reporting.
- Pair with CUPED. Delta method on the ratio of CUPED-adjusted metrics is the standard ratio-A/B test at scale.
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •reference: constant denominator reduces to Var(X)/n
- •example: hand-checked ratio on a tiny fixed dataset equals 1/12
- •sample: two noisy streams give a positive variance