Stan (software)

Stan
Original authorStan Development Team
ReleaseAugust 30, 2012 (2012-08-30)
Stable release
2.40.0 Edit this on Wikidata / 16 September 2026; 2 months ago (16 September 2026)
Written inC++
Operating systemUnix-like, Microsoft Windows, Mac OS X
PlatformIntel x86 - 32-bit, x64
TypeStatistical package
LicenseNew BSD License
Websitemc-stan.org
Repository

Stan is a probabilistic programming language for statistical inference written in C++. The Stan language is used to specify a (Bayesian) statistical model with an imperative program calculating the log probability density function.

Stan is licensed under the New BSD License. Stan is named in honour of Stanislaw Ulam, a pioneer of the Monte Carlo method.

Stan was created by a development team of 52 members, including Andrew Gelman, Bob Carpenter, Daniel Lee, Ben Goodrich, and others.

Example

A simple linear regression model can be described as yn=α+βxn+ϵn, where ϵn∼normal(0,σ). This can also be expressed as yn∼normal(α+βXn,σ). The latter form can be written in Stan as the following:

data {
  int<lower=0> N;
  vector[N] x;
  vector[N] y;
}
parameters {
  real alpha;
  real beta;
  real<lower=0> sigma;
}
model {
  y ~ normal(alpha + beta * x, sigma);
}

Interfaces

The Stan language itself can be accessed through several interfaces:

In addition, higher-level interfaces are provided by packages using Stan as a backend, primarily in the R language:

Algorithms

Stan implements gradient-based Markov chain Monte Carlo (MCMC) algorithms for Bayesian inference, stochastic, gradient-based variational Bayesian methods for approximate Bayesian inference, and gradient-based optimization for penalized maximum likelihood estimation.

Automatic differentiation

Stan implements reverse-mode automatic differentiation to calculate gradients of the model, which are required by HMC, NUTS, L-BFGS, BFGS, and variational inference. The automatic differentiation within Stan can be used outside of the probabilistic programming language.

Usage

Stan is used in fields including social science, pharmaceutical statistics, market research, and medical imaging.

See also