Learn R Programming

rstan (version 2.9.0-3)

rstan-package: RStan --- Rinterface to Stan

Description

Rinterface to Stan, which is a C++ package for obtaining Bayesian inference using the No-U-turn sampler, a variant of Hamiltonian Monte Carlo (see http://mc-stan.org/).

Arguments

Details

ll{ Package: rstan Type: Package Version: 2.9.2 Date: Feb 07, 2016 License: GPL-3 }

The RStan package provides an interface to Stan. For more information on Stan and its modeling language, see the Stan Modeling Language User's Guide and Reference Manual, which is available http://mc-stan.org/.

References

The Stan Development Team Stan Modeling Language User's Guide and Reference Manual. http://mc-stan.org/.

See Also

stan, stanfit

Examples

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

parameters {
  real mu;
} 

model {
  mu ~ normal(0, 10);
  y ~ normal(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)

# 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