Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2010 Jul;35(4):1-81.

PyMC: Bayesian Stochastic Modelling in Python

Affiliations

PyMC: Bayesian Stochastic Modelling in Python

Anand Patil et al. J Stat Softw. 2010 Jul.

Abstract

This user guide describes a Python package, PyMC, that allows users to efficiently code a probabilistic model and draw samples from its posterior distribution using Markov chain Monte Carlo techniques.

PubMed Disclaimer

Figures

Figure 1
Figure 1
Recorded coal mining disasters in the UK.
Figure 2
Figure 2
Directed acyclic graph of the relationships in the coal mining disaster model example.
Figure 3
Figure 3
Histogram of the marginal posterior probability of parameter l.
Figure 4
Figure 4
Temporal series and histogram of the samples drawn for s.
Figure 5
Figure 5
Trace and posterior distribution of the second missing data point in the example.
Figure 6
Figure 6
Directed graphical model example. Factor potentials are represented by rectangles and stochastic variables by ellipses.
Figure 7
Figure 7
The undirected version of the graphical model of Figure 6.
Figure 8
Figure 8
An example of a poorly-mixing sample in two dimensions. Notice that the chain is trapped in a region of low probability relative to the mean (dot) and variance (oval) of the true posterior quantity.
Figure 9
Figure 9
An example of metastability in a two-dimensional parameter space. The chain appears to be stable in one region of the parameter space for an extended period, then unpredictably jumps to another region of the space.
Figure 10
Figure 10
Sample plots of Geweke z-scores for a variable using geweke_plot. The occurrence of the scores well within 2 standard deviations of zero gives does not indicate lack of convergence (top), while deviations exceeding 2 standard deviations suggests that additional samples are required to achieve convergence (bottom).
Figure 11
Figure 11
Sample autocorrelation plots for two Poisson variables from coal mining disasters example model.
Figure 12
Figure 12
Data sampled from the posterior predictive distribution of a model for some observation x. The true value of x is shown by the dotted red line.
Figure 13
Figure 13
Plot of deviates of observed and simulated data from expected values. The cluster of points symmetrically about the 45 degree line (and the reported p value) suggests acceptable fit for the modeled parameter.

References

    1. Akaike H. Information Theory as an Extension of the Maximum Likelihood Principle. In: Petrov BN, Csaki F, editors. Second International Symposium on Information Theory. Akademiai Kiado; Budapest: 1973. pp. 267–281.
    1. Alted F, Vilata I, Prater S, Mas V, Hedley T, Valentino A, Whitaker J. PyTables User’s Guide: Hierarchical Datasets in Python – Release 2.2. 2010. URL http://www.pytables. org/
    1. Azzalini A. The Skew-Normal Probability Distribution (and Related Distributions, such as the Skew-t) 2010. URL http://azzalini.stat.unipd.it/SN/
    1. Bernardo JM, Berger J, Dawid AP, Smith JFM, editors. Bayesian Statistics 4. Oxford University Press; Oxford: 1992.
    1. Brooks SP, Catchpole EA, Morgan BJT. Bayesian Animal Survival Estimation. Statistical Science. 2000;15:357–376.

LinkOut - more resources