ArticleslgStudy

computer science

Stan (software)

Stan (software) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Stan (software) rather than just read about it. In short: 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 (software) — main illustration
Stan (software) — illustration

Key takeaways

  • Stan (software) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Stan (software) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Stan (software) from memory before moving on to harder problems.

Reference excerpt

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, pioneer of the Monte Carlo method. Stan was created by a development team consisting of 52 members that includes Andrew Gelman, Bob Carpenter, Daniel Lee, Ben Goodrich, and others.

Example A simple linear regression model can be described as y n = α + β x n + ϵ n {\displaystyle y_{n}=\alpha +\beta x_{n}+\epsilon _{n}} , where ϵ n ∼ normal ( 0 , σ ) {\displaystyle \epsilon _{n}\sim {\text{normal}}(0,\sigma )} . This can also be expressed as y n ∼ normal ( α + β X n , σ ) {\displaystyle y_{n}\sim {\text{normal}}(\alpha +\beta X_{n},\sigma )} . The latter form can be written in Stan as the following:

Interfaces The Stan language itself can be accessed through several interfaces:

CmdStan – a command-line executable for the shell, CmdStanR and rstan – R software libraries, CmdStanPy and PyStan – libraries for the Python programming language, CmdStan.rb - library for the Ruby programming language, MatlabStan – integration with the MATLAB numerical computing environment, Stan.jl – integration with the Julia programming language, StataStan – integration with Stata. Stan Playground - online at [1] In addition, higher-level interfaces are provided with packages using Stan as backend, primarily in the R language:

rstanarm provides a drop-in replacement for frequentist models provided by base R and lme4 using the R formula syntax; brms provides a wide array of linear and nonlinear models using the R formula syntax; prophet provides automated procedures for time series forecasting.

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.

MCMC algorithms: Hamiltonian Monte Carlo (HMC) No-U-Turn sampler (NUTS), a variant of HMC and Stan's default MCMC engine Variational inference algorithms: Automatic Differentiation Variational Inference Pathfinder: Parallel quasi-Newton variational inference Optimization algorithms: Limited-memory BFGS (L-BFGS) (Stan's default optimization algorithm) Broyden–Fletcher–Goldfarb–Shanno algorithm (BFGS) Laplace's approximation for classical standard error estimates and approximate Bayesian posteriors

Automatic differentiation Stan implements reverse-mode automatic differentiation to calculate gradients of the model, which is 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 PyMC is a probabilistic programming language in Python ArviZ a Python library for Exploratory Analysis of Bayesian Models

References

Further reading Carpenter, Bob; Gelman, Andrew; Hoffman, Matthew; Lee, Daniel; Goodrich, Ben; Betancourt, Michael; Brubaker, Marcus; Guo, Jiqiang; Li, Peter; Riddell, Allen (2017). "Stan: A Probabilistic Programming Language". Journal of Statistical Software. 76 (1): 1–32. doi:10.18637/jss.v076.i01. ISSN 1548-7660. PMC 9788645. PMID 36568334. Gelman, Andrew, Daniel Lee, and Jiqiang Guo (2015). Stan: A probabilistic programming language for Bayesian inference and optimization, Journal of Educational and Behavioral Statistics. Hoffman, Matthew D., Bob Carpenter, and Andrew Gelman (2012). Stan, scalable software for Bayesian modeling Archived 2015-01-21 at the Wayback Machine, Proceedings of the NIPS Workshop on Probabilistic Programming.

External links Stan web site Stan source, a Git repository hosted on GitHub

Worked examples

Example 1 — a first encounter with Stan (software)

Start with the simplest possible case. Write down what Stan (software) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Stan (software) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Stan (software) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Stan (software)

In research
Stan (software) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Stan (software) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Stan (software) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computational statistics, Domain-specific programming languages, Free Bayesian statistics software, so understanding it makes those chapters shorter.
In everyday life
Look for Stan (software) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Stan (software)” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Stan (software) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Stan (software) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Stan (software) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Stan (software) in simple terms?

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.

Why does Stan (software) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Stan (software)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Stan (software).

Tags

  • Computational statistics
  • Domain-specific programming languages
  • Free Bayesian statistics software
  • Monte Carlo software
  • Numerical programming languages
  • Probabilistic software

Keep exploring