stan-dev/rstan
RStan, the R interface to Stan
What is RStan?
RStan is the official R package that lets you use Stan, a powerful probabilistic programming language, from within the R statistical environment. Stan performs Bayesian inference via modern Markov‑chain Monte Carlo (MCMC) and variational algorithms, so RStan is essentially a bridge that lets R users write Stan models, compile them, and run inference without leaving R.
Key capabilities
| Capability | What it means for you |
|---|---|
| Write Stan models in R | Define a model in Stan’s own language (a separate .stan file) and call it from R with stan() or sampling(). |
| Fast inference engines | Uses Stan’s C++‑based Hamiltonian Monte Carlo (NUTS) and variational inference under the hood, giving state‑of‑the‑art Bayesian posterior sampling. |
| Automatic differentiation | Stan’s autodiff computes gradients of the log‑posterior efficiently, which is essential for HMC. |
| Diagnostics & post‑processing | Returns an stanfit object that integrates with R’s coda, bayesplot, and other packages for convergence checks, trace plots, and posterior summaries. |
| Cross‑platform | Works on Windows, macOS, and Linux; binaries are available on CRAN for easy installation. |
| Extensible | You can add custom C++ functions to a Stan model and expose them to R. |
How to get started
- Install –
install.packages("rstan")(or follow the detailed RStan Getting Started wiki for system‑specific steps). - Write a model – create a file
model.stancontaining Stan code (e.g., a simple linear regression). - Fit the model – in R:
library(rstan) fit <- stan(file = "model.stan", data = my_data, iter = 2000, chains = 4) print(fit) plot(fit) - Explore results – use
summary(fit),extract(fit), or thebayesplotpackage for visual diagnostics.
The repository’s README points to a wiki page with step‑by‑step installation instructions and translations for French, Japanese, Chinese, and Portuguese.
Where to find more information
- Online docs & vignettes – https://mc-stan.org/rstan/
- Stan language reference – https://mc-stan.org/users/documentation/
- Community help – Stan Discourse forum (https://discourse.mc-stan.org)
- Bug reports / feature requests – GitHub Issues (https://github.com/stan-dev/rstan/issues)
Licensing & contribution policy
- The R package itself is released under GPL‑3.
- The bundled Stan code is under the new BSD license.
- Contributions must follow the Stan AI Contribution Policy, ensuring responsible use of AI‑related tooling.
Bottom line: RStan lets R users tap into Stan’s cutting‑edge Bayesian inference engine directly from their familiar R workflow, making sophisticated probabilistic modeling accessible without leaving the R ecosystem.
Related
- Project
- Project
- Project
- Project
- Project