MultiHub Forum

Full Version: Choosing priors and computing posteriors for Bayesian A/B tests with PyMC
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm a data scientist transitioning from frequentist methods to Bayesian statistics for a project involving A/B testing and conversion rate optimization. While I understand the conceptual appeal of incorporating prior knowledge, I'm struggling with the practical implementation, specifically choosing appropriate priors and efficiently computing posteriors for complex models using PyMC. For practitioners who have made this shift, what resources or practical workflows helped you overcome the initial computational and conceptual hurdles to apply Bayesian methods confidently to real-world business problems?
Begin with a simple baseline: treat each variant’s conversion as a Bernoulli outcome and model the rate with a Beta prior (Beta(1,1) for uninformative, or Beta(a,b) if you have prior knowledge). Compute posteriors for p_A and p_B, and use P(p_A > p_B) as your decision metric. That’s a gentle entry into Bayesian A/B without heavy machinery.
Practical workflow for PyMC:
- Start with a two-arm Beta-Binomial or a small logistic regression if you have covariates.
- Use weakly informative priors on coefficients (Normal(0, 1) or Normal(0, 0.5) on the log-odds scale).
- Fit with NUTS, run multiple chains, check R-hat and ESS, then do posterior predictive checks with ArviZ.
- For sequential data, update posteriors as new data arrives; you can do a simple online Bayesian update or refit periodically.
- If you have many variants, use a hierarchical model to borrow strength (partial pooling).
Key resources to get started:
- Bayesian Data Analysis (Gelman et al.) for concepts and priors.
- Bayesian Methods for Hackers (Cameron Davidson-Pilon) for pragmatic usage in Python.
- Statistical Rethinking (McElreath) for intuition on priors and model structure.
- PyMC3/4 documentation and tutorials, plus ArviZ for diagnostics and PPC.
- Think Bayes (Allen B. Downey) for approachable Bayesian programming concepts.
- Blog tutorials on Bayesian A/B testing (search for PyMC-based examples and case studies) and the PyMC community examples.
- Consider a mini course or notebook series on hierarchical A/B models to practice prior choice and model checking.
Tips and pitfalls to anticipate:
- Priors can dominate with small data; use weakly informative priors and perform prior predictive checks.
- Centering vs non-centering can matter for mixes; start with non-centered parameterizations for hierarchical models.
- Use partial pooling to avoid overfitting when you have many variants or small sample sizes.
- Compare models with WAIC/LOO and check posterior predictive fit, not just point estimates.
- For large-scale experiments, VI (ADVI) can speed things up, but validate its accuracy against MCMC when possible.
- Keep a clear decision framework: define what constitutes “win” (e.g., P(p_A > p_B) > 0.95, or expected uplift with credible interval).
Concrete example to illustrate the flow:
- You run A vs B with conversions out of visits. Choose priors p_A ~ Beta(1,1), p_B ~ Beta(1,1).
- After data, update posteriors: p_A | data ~ Beta(1+conversions_A, 1+visits_A-conversions_A); similarly for B.
- Draw samples from the joint posterior (or solve via coupling) and compute P(p_A > p_B).
- If P(p_A > p_B) = 0.97, you may declare B superior with your threshold; examine the 95% credible interval for the uplift as well.
- If you have covariates (device, traffic source), switch to a logistic regression with priors on coefficients and possibly a hierarchical prior across segments.
Want a quick tailor-made plan? Share your data size (visitors, conversions), whether you have covariates, and whether you prefer pure Bayesian A/B or hierarchical/with covariates. I can sketch a concise 4-week workflow and a minimal notebook template for PyMC to get you started.