June 25, 2017

Some other things you ought to know about Stan

Hamiltonian Monte Carlo

  • To produce draws from the posterior distribution, Stan uses a variation of Hamiltonian Monte Carlo (HMC) called the No U-Turn Sampler (NUTS).
  • HMC is a variation on the Metropolis-Hastings (M-H) algorithm, but it uses the gradient of the distribution to more quickly explore the bulk of the posterior.
  • NUTS further improves on HMC by automating tuning of the HMC algorithm.
  • For an overview of HMC see the MCMC Handbook Chapter by Radford Neal and for more on NUTS see Hoffman and Gelman.

There are other ways to interface with Stan

  • RStan (R)
  • PyStan (Python)
  • CmdStan (shell, command-line terminal)
  • MatlabStan (MATLAB)
  • Stan.jl (Julia)
  • StataStan (Stata)
  • MathematicaStan (Mathematica)

Stan supports other approches to inference

  • Hamiltonian Monte Carlo / NUTS
    • Default algorithm we have used in this tutorial
  • Variational Bayes
    • A fast approximation to full Bayesian inference
    • Somewhat experimental in Stan
  • “Optimization”
    • Routines that find point estimates of parameters rather than the full posterior, e.g. maximum likelihood (ML) or maximum a posteriori (MAP)

You can specify the likelihood directly in Stan

Advanced Stan users sometimes find it easier to specify the full likelihood of the model directly rather than using the sampling statements we have shown here.

y ~ normal(mu, sigma);

is equivalent to

target += normal_lpdf(y | mu, sigma);

Examples of when this is handy are beyond the scope of this tutorial.

Useful R packages for working with Stan

  • rstan
  • coda
    • tools for summarizing draws
  • bayesplot
    • tools for summarizing draws
  • ShinyStan
    • a GUI for exploring posterior draws
  • RStanArm
    • Provides an “R-like” interface with formula notation for Stan

Learning more about Stan

Where can you find help with Stan?

  • The Stan forum is very active and the Stan development team often provides answers to questions.
    • A Google search like “multinomial logit in Stan” will often lead you to the forums.
  • Keep in mind that Stan develops over time, so you want to check the date of any post.

Stan examples

  • The Stan website maintains a library of Stan examples.
  • We often begin developing a new model by finding an example that is close to what we want and then modifying it.

Popular Stan conferences

Who is responsible for Stan?

  • Stan is maintained by the Stan development team, which consistes of consists of volunteers from around the world.
  • Key players include Andrew Gelman and Bob Carpenter, but they have been joined by many others.

Books about Stan