Stan Development Team

RStan is the R interface to the Stan C++ package. The RStan interface (rstan R package) provides:

  • Full Bayesian inference using the No-U-Turn sampler (NUTS), a variant of Hamiltonian Monte Carlo (HMC)

  • Approximate Bayesian inference using automatic differentiation variational inference (ADVI)

  • Penalized maximum likelihood estimation using L-BFGS optimization

For documentation on Stan itself, including the manual and user guide for the modeling language, case studies and worked examples, and other tutorial information visit the Users section of the Stan website:

Other R packages from the Stan Development Team

Various related R packages are also available from the Stan Development Team including these and more:

PackageDescriptionDocWebsite
bayesplotggplot-based plotting of parameter estimates, diagnostics, and posterior predictive checks.bayesplot-packagemc-stan.org/bayesplot
shinystanInteractive GUI for exploring MCMC output.shinystan-packagemc-stan.org/shinystan
looOut-of-sample predictive performance estimates and model comparison.loo-packagemc-stan.org/loo
rstanarmR formula interface for applied regression modeling.rstanarm-packagemc-stan.org/rstanarm
rstantoolsTools for developers of R packages interfacing with Stan.rstantools-packagemc-stan.org/rstantools

Author

Jonah Gabry (author)<jonah.sol.gabry@columbia.edu>
Ben Goodrich (maintainer, author)<benjamin.goodrich@columbia.edu>
Jiqiang Guo (author)<guojq28@gmail.com>

There are also many other important contributors to RStan (github.com/rstan). Please use 'Stan Development Team' whenever citing the R interface to Stan. A BibTex entry is available from https://mc-stan.org/rstan/authors or citation("rstan").

See also

Examples

if (FALSE) {

stanmodelcode <- "
data {
  int<lower=0> N;
  real y[N];
}

parameters {
  real mu;
}

model {
  target += normal_lpdf(mu | 0, 10);
  target += normal_lpdf(y  | mu, 1);
}
"

y <- rnorm(20)
dat <- list(N = 20, y = y);
fit <- stan(model_code = stanmodelcode, model_name = "example",
            data = dat, iter = 2012, chains = 3, verbose = TRUE,
            sample_file = file.path(tempdir(), 'norm.csv'))
print(fit)

# extract samples
e <- extract(fit, permuted = FALSE) # return a list of arrays
str(e)

arr <- as.array(fit) # return an array
str(arr)

mat <- as.matrix(fit) # return a matrix
str(mat)
}