Comparing Bayesian and Frequentist Decision Rules in A/B Testing
Statistics & ExperimentsModel answerLast updated
Analyze an A/B experiment using Bayesian posteriors, expected loss decision rules, sequential peeking effects, and prior calibration techniques.
You run an online experiment evaluating a proposed change against a baseline control. Both arms start with uninformative $\text{Beta}(1, 1)$ priors over their respective success probabilities. You collect sample sizes of $n_A = 10,000$ and $n_B = 10,000$, observing $k_A = 500$ and $k_B = 515$ conversions.
Address each of the following components:
- Posterior Computations: Compute the exact parameters of the posterior distributions for both variants. Derive the posterior distribution of the absolute conversion rate difference $D = \theta_B - \theta_A$ using a normal approximation, and calculate the posterior probability that the treatment outperforms the control ($\mathbb{P}(D > 0)$).
- Decision Theory Framework: Formulate a quantitative decision rule grounded in expected loss under asymmetric costs (where shipping a non-performing feature incurs a higher cost than withholding a performant one). Calculate the expected loss for both actions based on the experimental data.
- Sequential Monitoring & Methodology Comparison: Contrast the decision framework with standard frequentist hypothesis testing. Explain the consequences of continuous monitoring (optional stopping) under both frameworks, detailing techniques such as $\alpha$-spending and always-valid inference.
- Prior Calibration & Shrinkage: Explain why standard uninformative priors (like $\text{Beta}(1, 1)$) can lead to over-optimistic conclusions (the winner's curse). Detail how to construct realistic, calibrated prior distributions using empirical Bayes or expert elicitation.
Hints
Hint 1
Recall that the Beta distribution is the conjugate prior for Binomial data, yielding a Beta(alpha + successes, beta + failures) posterior.
Hint 2
For large sample sizes, the difference between two Beta-distributed random variables can be closely approximated by a Normal distribution whose mean is the difference of posterior means and variance is the sum of posterior variances.
Hint 3
Expected loss for a decision involves integrating the magnitude of regret over the region where the decision is incorrect, which can be evaluated analytically for Gaussian approximations using the standard normal PDF and CDF.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Posterior Distributions & Probability of Superiority
Posterior Calculations
With binary conversion outcomes and independent prior distributions $\theta_A, \theta_B \sim \text{Beta}(1, 1)$, the posterior distributions follow conjugate updating rules:
$$\text{Posterior} = \text{Beta}(\alpha + k, \beta + n - k)$$
-
Variant A (Control): $n_A = 10,000$, $k_A = 500$ $$\theta_A \mid \text{data} \sim \text{Beta}(1 + 500, 1 + 9500) = \text{Beta}(501, 9501)$$ $$\mathbb{E}[\theta_A] = \frac{501}{10002} \approx 0.05009$$ $$\text{Var}(\theta_A) = \frac{\alpha \beta}{(\alpha + \beta)^2 (\alpha + \beta + 1)} = \frac{501 \cdot 9501}{(10002)^2 \cdot 10003} \approx 4.757 \times 10^{-6} \quad (\text{SD} \approx 0.00218)$$
-
Variant B (Treatment): $n_B = 10,000$, $k_B = 515$ $$\theta_B \mid \text{data} \sim \text{Beta}(1 + 515, 1 + 9486) = \text{Beta}(516, 9486)$$ $$\mathbb{E}[\theta_B] = \frac{516}{10002} \approx 0.05159$$ $$\text{Var}(\theta_B) = \frac{516 \cdot 9486}{(10002)^2 \cdot 10003} \approx 4.891 \times 10^{-6} \quad (\text{SD} \approx 0.00221)$$
Absolute Lift Distribution
Let $D = \theta_B - \theta_A$. Because $n_A, n_B$ are large, $D$ is well-approximated by a Gaussian distribution $N(\mu_D, \sigma_D^2)$:
$$\mu_D = \mathbb{E}[\theta_B] - \mathbb{E}[\theta_A] = 0.05159 - 0.05009 \approx 0.00150 \quad (0.15 \text{ percentage points})$$ $$\sigma_D^2 = \text{Var}(\theta_A) + \text{Var}(\theta_B) \approx 4.757 \times 10^{-6} + 4.891 \times 10^{-6} = 9.648 \times 10^{-6}$$ $$\sigma_D = \sqrt{9.648 \times 10^{-6}} \approx 0.00311$$
Posterior Probability of Superiority ($\mathbb{P}(D > 0)$)
Using the normal approximation:
$$Z = \frac{0 - \mu_D}{\sigma_D} = \frac{0 - 0.00150}{0.00311} \approx -0.482$$ $$\mathbb{P}(D > 0) = 1 - \Phi(-0.482) = \Phi(0.482) \approx 0.685 \quad (68.5%)$$
The equal-tailed $95%$ credible interval for the difference is:
$$0.00150 \pm 1.96 \times 0.00311 \implies [-0.0046, +0.0076]$$
2. Decision Theory Framework & Expected Loss
Relying solely on $\mathbb{P}(\theta_B > \theta_A) > 0.5$ as a deployment rule is insufficient because it ignores the magnitude of gains or losses and the fixed costs of engineering deployment.
Mathematical Formulation of Loss
Define the continuous regret loss functions for each action:
- Loss from deploying B: $L_{\text{deploy B}}(D) = \max(-D, 0)$
- Loss from retaining A: $L_{\text{retain A}}(D) = \max(D, 0)$
For a normal posterior distribution $D \sim N(\mu, \sigma^2)$, the expected regret can be calculated analytically using the standard normal PDF $\phi(z)$ and CDF $\Phi(z)$, where $z = \frac{\mu}{\sigma}$:
$$\mathbb{E}[L_{\text{deploy B}}] = \int_{-\infty}^{0} (-u) \frac{1}{\sigma}\phi\left(\frac{u-\mu}{\sigma}\right) du = \sigma \phi(z) - \mu \Phi(-z)$$ $$\mathbb{E}[L_{\text{retain A}}] = \int_{0}^{\infty} u \frac{1}{\sigma}\phi\left(\frac{u-\mu}{\sigma}\right) du = \sigma \phi(z) + \mu \Phi(z)$$
With $z = \frac{0.00150}{0.00311} \approx 0.482$:
- $\phi(0.482) \approx 0.3551$
- $\Phi(0.482) \approx 0.6851$
- $\Phi(-0.482) \approx 0.3149$
Calculating the expectations:
$$\mathbb{E}[L_{\text{deploy B}}] = (0.00311 \times 0.3551) - (0.00150 \times 0.3149) \approx 0.001104 - 0.000472 = 0.000632 \quad (0.0632 \text{ percentage points})$$ $$\mathbb{E}[L_{\text{retain A}}] = (0.00311 \times 0.3551) + (0.00150 \times 0.6851) \approx 0.001104 + 0.001028 = 0.002132 \quad (0.2132 \text{ percentage points})$$
(Verification check: $\mathbb{E}[L_{\text{retain A}}] - \mathbb{E}[L_{\text{deploy B}}] = \mu = 0.00150$.)
Asymmetric Costs & Decision Rule
Let:
- $c_{\text{ship}}$: Cost multiplier for deploying a neutral or negative feature (code complexity, maintenance overhead, risk of undetected regressions).
- $c_{\text{miss}}$: Cost multiplier for failing to ship a positive feature (opportunity cost).
- $K$: Fixed cost of deployment.
Decision Rule: Deploy Variant B if and only if:
$$c_{\text{ship}} \cdot \mathbb{E}[L_{\text{deploy B}}] + K < c_{\text{miss}} \cdot \mathbb{E}[L_{\text{retain A}}]$$
Assuming $K = 0$ and asymmetric operational costs where releasing a bad feature is 3 times worse than missing a good feature ($c_{\text{ship}} = 3$, $c_{\text{miss}} = 1$):
$$\text{Expected Loss (B)} = 3 \times 0.000632 = 0.001896$$ $$\text{Expected Loss (A)} = 1 \times 0.002132 = 0.002132$$
Although $0.001896 < 0.002132$ favors deploying Variant B, the expected loss for both choices remains substantial compared to typical threshold standards (e.g., stopping threshold $\epsilon = 0.0001$). This indicates high posterior uncertainty, recommending continued data collection rather than an immediate decision.
3. Comparison with Frequentist Testing and Sequential Monitoring
Frequentist Analysis
Under a standard two-sample proportion $z$-test:
- Pooled conversion rate: $\hat{p} = \frac{500 + 515}{20000} = 0.05075$
- Standard error: $\text{SE} = \sqrt{0.05075 \times (1 - 0.05075) \times \left(\frac{1}{10000} + \frac{1}{10000}\right)} \approx 0.00310$
- Test statistic: $z = \frac{0.0515 - 0.0500}{0.00310} \approx 0.484$
- Two-sided $p$-value: $p = 2 \times (1 - \Phi(0.484)) \approx 0.628$
At standard significance levels ($\alpha = 0.05$), the frequentist test fails to reject the null hypothesis. Detecting a true lift of $0.15$ percentage points at $80%$ statistical power would require approximately $330,000$ users per arm.
Continuous Monitoring & Optional Stopping
| Aspect | Frequentist Framework | Bayesian Framework |
|---|---|---|
| Likelihood Principle | Dependent on the sampling plan and stopping intention. | Complies with the likelihood principle; posterior depends only on observed data. |
| Peeking Impact | Repeated evaluations inflate Type I error rates (up to ~20-30% across multiple checks). | Posterior probabilities remain updated, but stopping thresholds based on $\mathbb{P}(\text{lift} > 0) > 0.95$ still inflate frequentist false-positive rates under a flat prior. |
| Mitigation Techniques | Alpha-spending functions (e.g., O'Brien-Fleming, Pocock) or Always-Valid $p$-values via Mixture Sequential Probability Ratio Tests (mSPRT). | Expected Loss Thresholding ($\text{Loss} < \epsilon$), shrinkage priors, and Bayes factor thresholds. |
Operational & Stakeholder Implications
- Communication: Stakeholders frequently misinterpret $p$-values ($p = 0.628$) as "there is a $62.8%$ chance the null hypothesis is true." Conversely, Bayesian metrics ("$68.5%$ chance B is better, with an expected regret of $0.063$ percentage points") provide more direct business interpretations, provided credible intervals are also reported.
- Governance: Enterprise execution requires pre-registered metrics, bounds on maximum duration, and minimum runtimes (e.g., 7-day cycles) to prevent stopping early due to day-of-week seasonality or novelty bias.
4. Prior Calibration & Shrinkage Techniques
The Winner's Curse of Flat Priors
Using a $\text{Beta}(1,1)$ prior assumes that all conversion rates $\theta \in [0, 1]$ are equally likely. This assigns substantial probability mass to absurd effect sizes (such as absolute rate jumps of $\pm 20%$).
When true effect sizes are small (typically $< 1-2%$ relative lift), uninformative priors over-index on sample noise, causing inflated effect estimates in early stopping scenarios—a phenomenon known as the Winner's Curse.
Constructing Calibrated Priors
To prevent over-optimism, parameterize the prior distribution directly over the parameter difference $D \sim N(0, \tau^2)$, retaining a baseline prior for $\theta_A$ derived from historical data.
Flat Prior Beta(1,1) Informative/Shrinkage Prior
(High weight on unrealistic lifts) (Centered at 0, constrained variance)
▲ ▲
│ ┌───────┐ │ ┌─┐
│ ┌┘ └┐ │ ┌┘ └┐
│ ┌┘ └┐ │ ┌┘ └┐
└─┴───────────┴──► └─────┴─────┴────►
-20% 0 +20% -2% 0 +2%
Empirical Bayes Example
Suppose historical data across hundreds of experiments indicates that relative lifts cluster tightly around zero with a standard deviation of $\tau = 0.001$ ($0.1$ percentage points).
Updating the parameter difference $D$ using Gaussian conjugacy yields:
$$\mu_{\text{post}} = \frac{\frac{0}{\tau^2} + \frac{\hat{\mu}_D}{\sigma_D^2}}{\frac{1}{\tau^2} + \frac{1}{\sigma_D^2}} = \hat{\mu}_D \left( \frac{\tau^2}{\tau^2 + \sigma_D^2} \right)$$
Plugging in $\tau^2 = 1 \times 10^{-6}$, $\hat{\mu}_D = 0.00150$, and $\sigma_D^2 = 9.648 \times 10^{-6}$:
$$\text{Shrinkage Factor} = \frac{1 \times 10^{-6}}{1 \times 10^{-6} + 9.648 \times 10^{-6}} \approx 0.0939$$ $$\mu_{\text{post}} = 0.00150 \times 0.0939 \approx 0.000141$$ $$\sigma_{\text{post}}^2 = \frac{1}{\frac{1}{1 \times 10^{-6}} + \frac{1}{9.648 \times 10^{-6}}} \approx 9.06 \times 10^{-7} \quad (\sigma_{\text{post}} \approx 0.000952)$$
Recalculating the posterior probability of superiority under shrinkage:
$$Z_{\text{calibrated}} = \frac{0.000141}{0.000952} \approx 0.148$$ $$\mathbb{P}(D > 0 \mid \text{data, calibrated prior}) = \Phi(0.148) \approx 0.559 \quad (55.9%)$$
The adjusted probability drops from $68.5%$ to $55.9%$, pulling the decision back toward the null and shielding the team from acting on sampling noise.
Practical Guidelines for Prior Elicitation
- Empirical Historical Aggregation: Fit a prior model (such as a Gaussian Mixture Model or Student's $t$-distribution) to historical experiment metrics across similar domain features.
- Quantile Elicitation: Ask domain experts for lower and upper quantiles (e.g., $10^{\text{th}}$ and $90^{\text{th}}$ percentiles) for potential feature impacts rather than point estimates.
- Prior Predictive Checks: Simulate pseudo-data generated from candidate priors to verify that the implied lift bounds align with realistic business expectations.
- Sensitivity Testing: Evaluate decisions across a spectrum of prior variances ($\tau$) to ensure conclusions are robust to the choice of prior.