stan-dev/rstanarm

rstanarm R package for Bayesian applied regression modeling

What it solves

rstanarm provides an accessible entry point for Bayesian applied regression modeling in R. It solves the problem of the steep learning curve associated with Bayesian software by emulating the syntax and behavior of common frequentist model-fitting functions (like glm or lm), allowing users to perform Bayesian inference without needing to write complex Stan code manually.

How it works

The package acts as an interface to the rstan package and the Stan probabilistic programming language. It uses pre-compiled Stan programs that are optimized for numerical stability and sampling efficiency. Users specify models using standard R formulas and data frames, and the package handles the translation to Stan's back-end estimation.

It supports several estimation algorithms:

  • Sampling (MCMC): The default and most reliable method using Hamiltonian Monte Carlo (HMC).
  • Mean-field Variational Inference: A fast approximation of the posterior distribution.
  • Full-rank Variational Inference: A more realistic but computationally heavier approximation than mean-field.
  • Optimizing: Finds the posterior mode using the L-BFGS algorithm (currently supported for stan_glm).

Who it’s for

  • Frequentist researchers who want to transition to Bayesian inference using familiar R syntax.
  • Experienced Bayesian users who want to avoid writing their own Stan models from scratch and use professionally implemented, stable pre-compiled models.

Highlights

  • Broad Model Support: Includes linear (stan_lm), generalized linear (stan_glm), mixed-effects (stan_glmer), nonlinear mixed-effects (stan_nlmer), and joint models for longitudinal and survival data (stan_jm).
  • Integration with Ecosystem: Works seamlessly with bayesplot for posterior predictive checks, loo for cross-validation and model comparison, and shinystan for GUI-based diagnostics.
  • Customizable Priors: Allows users to specify prior distributions for model parameters to incorporate prior knowledge.
  • Numerical Stability: Uses pre-compiled programs written by Stan developers to minimize sampling problems.

Related

  • Project
  • Project
  • Project
  • Project
  • Project