# 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