Frequentism and Bayesianism IV: How to be a Bayesian in Python
bayesian-statisticsmcmcpythonstatistics
Abstraction: Comparing emcee, PyMC, and PyStan for Bayesian MCMC in Python
Key points:
- Three Python MCMC packages compared on a 3-parameter linear regression with nuisance scatter: emcee, PyMC (v2), and PyStan
- emcee is pure Python, lightweight, uses affine-invariant ensemble sampling; installs easily via pip; ~6 sec for 100k samples
- PyMC2 uses Metropolis-Hastings, requires Fortran compiler, Pythonic API with decorator syntax; ~17 sec; PyMC3 (alpha) is a complete rewrite with much better performance
- PyStan wraps Stan (C++), uses No-U-Turn Sampler, requires learning Stan model language, ~20 sec compilation + ~6 sec; most powerful but steepest learning curve
- Flat priors are not always uninformative; Jeffreys prior (1/σ for scale parameters; (1+β²)^{-3/2} for slope) is preferred for symmetry/maximum entropy reasons
- All three packages agree on posterior contours; true parameters (25, 0.5) fall within 1-σ error ellipse
Connections: Jake Vanderplas · Pymc · Pystan · Bayesian Statistics · Mcmc
Source: http://jakevdp.github.io/blog/2014/06/14/frequentism-and-bayesianism-4-bayesian-in-python/