Skip to content
SciStack

Bayesian inference

Priors, likelihoods, posteriors, and sampling them with MCMC to estimate parameters with honest uncertainty.

Test 20 valves under load and none of them fails. The textbook estimate of the failure rate is zero, with a standard error of zero, and nobody believes it. Bayesian inference starts instead from a prior, here every failure rate between 0 and 1 equally likely, and updates it with the data to a posterior: with 95 % probability the failure rate is below 13 %. That is what people come here for, a probability distribution for the parameter itself rather than a statement about imagined repeated experiments. The same reasoning dates a sediment core from a handful of radiocarbon ages, estimates rate constants from a noisy kinetics run, infers mutation rates in genetics, and pools measurements from many detectors or patients into a hierarchical model in which each group learns from the others.

A posterior with more than two or three parameters is sampled rather than computed, by Markov chain Monte Carlo. In Python, PyMC lets you write the model as code and samples it with the No-U-Turn sampler, emcee runs an ensemble sampler, EnsembleSampler, that needs nothing but a function returning the log posterior, and ArviZ reads the output of both for diagnostics and plots. In Julia, Turing.jl declares the model with the @model macro and samples it with NUTS. Whatever the library, check the chains before you read the answer: run four chains from different starting points and do not trust a parameter whose R-hat exceeds 1.01.

Start with one parameter whose posterior has a closed form, such as the valve test, and watch prior and data pull against each other. Then fit a straight line with a sampler, then build a hierarchical model, then compare models. Confidence intervals and hypothesis tests belong to statistics, the sampling algorithms themselves to Monte Carlo.

What belongs here

Estimating parameters and comparing models with probability distributions: priors, likelihoods, posteriors, credible intervals, hierarchical models, model comparison, and the samplers that make it practical (MCMC, probabilistic programming). Frequentist tests and confidence intervals belong to statistics; random number generation and Monte Carlo integration to monte-carlo.

0 tutorials by type and language

PythonJulia
Concept – –
Tool – –
Recipe – –
Visualization – –
Project – –