rstan (version 2.17.3)

rstan-package: RStan --- R interface to Stan

Description

mc-stan.org Stan Development Team

RStan is the R interface to the Stan C++ package. RStan 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 the Stan modeling language see the Stan Modeling Language User's Guide and Reference Manual.

Arguments

Other R packages from the Stan Development Team

Various related R packages are also available from the Stan Development Team:

Package Description Link
bayesplot ggplot-based plotting library for graphing parameter estimates, MCMC diagnostics, and posterior predictive checks. bayesplot-package
shinystan Interactive visual summaries and advanced posterior analysis of MCMC output. shinystan-package
loo Out-of-sample predictive performance estimates and model comparison. loo-package
rstanarm R formula interface for Bayesian applied regression modeling. rstanarm-package
rstantools Tools for developers of R packages interfacing with Stan. rstantools-package

See Also

Examples

Run this code
# NOT RUN {
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, sample_file = 'norm.csv',
            verbose = TRUE) 
print(fit)
traceplot(fit)

# extract samples 
e <- extract(fit, permuted = TRUE) # return a list of arrays 
mu <- e$mu 

m <- extract(fit, permuted = FALSE, inc_warmup = FALSE) # return an array 
print(dimnames(m))

# using as.array directly on stanfit objects 
m2 <- as.array(fit)

# }

Run the code above in your browser using DataLab