Bayesian Data Analysis, 3rd
Doing Bayesian Data Analysis, 2nd
http://www.sumsar.net/blog/2013/06/three-ways-to-run-bayesian-models-in-r/
http://blog.xavier-fim.net/2012/10/processing-stan-samples-with-ggmcmc-2/
library(magrittr)
library(rstan)
load("../datasets/NorthCarolina_data.dat")
set.seed(201502141)
infantsSample <- infants[sample(x = seq_len(nrow(infants)), size = 100),]
tableone::CreateTableOne(data = infantsSample) %>% print
## NOTE: no factor/logical/character variables supplied, using CreateContTable()
##
## Overall
## n 100
## race (mean (sd)) 0.25 (0.44)
## sex (mean (sd)) 0.53 (0.50)
## mage (mean (sd)) 27.56 (5.45)
## smoker (mean (sd)) 0.12 (0.33)
## gained (mean (sd)) 31.65 (15.18)
## weight (mean (sd)) 3.16 (0.56)
## weeks (mean (sd)) 38.18 (2.55)
## dTime (mean (sd)) 999.00 (0.00)
tableone::CreateTableOne(data = infantsSample) %>% print(nonnormal = TRUE)
## NOTE: no factor/logical/character variables supplied, using CreateContTable()
##
## Overall
## n 100
## race (median [IQR]) 0.00 [0.00, 0.25]
## sex (median [IQR]) 1.00 [0.00, 1.00]
## mage (median [IQR]) 28.00 [23.00, 31.00]
## smoker (median [IQR]) 0.00 [0.00, 0.00]
## gained (median [IQR]) 30.00 [20.00, 40.00]
## weight (median [IQR]) 3.23 [2.81, 3.60]
## weeks (median [IQR]) 38.00 [37.00, 40.00]
## dTime (median [IQR]) 999.00 [999.00, 999.00]
## Population true values
infants$weight %>% mean
## [1] 3.276151
infants$weight %>% var
## [1] 0.3928646
infants$weight %>% sd
## [1] 0.6267891
infants_dat <- list(alpha = 1, beta = 1,
N = nrow(infantsSample),
y = infantsSample$weight)
fileName <- "./Homework_2KY_stan.stan"
stan_code <- readChar(fileName, file.info(fileName)$size)
cat(stan_code)
## data {
## // Prior alpha
## int alpha;
## // Prior beta
## int beta;
## // Define variables in data
## // Number of observations (an integer)
## int<lower=0> N;
## // Birthweight outcome (a real vector of length N)
## real y[N];
## }
##
## parameters {
## // Define parameters to estimate
## // Population mean (a real number)
## real mu;
## // Population variance (a positive real number)
## real<lower=0> sigmaSq;
## }
##
## transformed parameters {
## // Population standard deviation (a positive real number)
## real<lower=0> sigma;
## // Standard deviation (derived from variance)
## sigma <- sqrt(sigmaSq);
## }
##
## model {
## // Prior part of Bayesian inference
## // Flat prior for mu (no need to specify if non-informative)
## // sigma^2 has inverse gamma (alpha = 1, beta = 1) prior
## sigmaSq ~ inv_gamma(alpha, beta);
##
## // Likelihood part of Bayesian inference
## // Outcome model N(mu, sigma^2) (use SD rather than Var)
## y ~ normal(mu, sigma);
## }
fit <- stan(model_code = stan_code, data = infants_dat,
## file = "./Homework_2KY_stan.stan", # External file method
iter = 10^4, warmup = 10^3, chains = 3, thin = 10)
##
## TRANSLATING MODEL 'stan_code' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'stan_code' NOW.
## In file included from file783117766bf.cpp:8:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:17:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev.hpp:5:
## /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'static' function 'set_zero_all_adjoints' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
## static void set_zero_all_adjoints() {
## ^
## In file included from file783117766bf.cpp:8:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:21:
## /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/io/dump.hpp:26:14: warning: function 'product' is not needed and will not be emitted [-Wunneeded-internal-declaration]
## size_t product(std::vector<size_t> dims) {
## ^
## 2 warnings generated.
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 1).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.013401 seconds (Warm-up)
## # 0.119585 seconds (Sampling)
## # 0.132986 seconds (Total)
##
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 2).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.013601 seconds (Warm-up)
## # 0.14266 seconds (Sampling)
## # 0.156261 seconds (Total)
##
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 3).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.015256 seconds (Warm-up)
## # 0.103726 seconds (Sampling)
## # 0.118982 seconds (Total)
## Show model results
fit
## Inference for Stan model: stan_code.
## 3 chains, each with iter=10000; warmup=1000; thin=10;
## post-warmup draws per chain=900, total post-warmup draws=2700.
##
## mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
## mu 3.16 0.00 0.06 3.05 3.12 3.16 3.20 3.28 2562 1
## sigmaSq 0.33 0.00 0.05 0.25 0.29 0.33 0.36 0.43 2700 1
## sigma 0.57 0.00 0.04 0.50 0.54 0.57 0.60 0.66 2700 1
## lp__ 5.93 0.02 1.04 3.12 5.56 6.24 6.67 6.94 2700 1
##
## Samples were drawn using NUTS(diag_e) at Mon Feb 23 12:56:37 2015.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).
plot(fit)
traceplot(fit, inc_warmup = FALSE)
## Extract data
s <- rstan::extract(fit, inc_warmup = FALSE)
summary(s$mu)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.964 3.121 3.161 3.161 3.201 3.389
summary(s$sigmaSq)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.2099 0.2947 0.3255 0.3295 0.3587 0.5292
infants_dat$alpha <- 2; infants_dat$beta <- 1
fit2 <- stan(model_code = stan_code, data = infants_dat,
iter = 10^4, warmup = 10^3, chains = 3, thin = 10)
##
## TRANSLATING MODEL 'stan_code' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'stan_code' NOW.
## In file included from file78354a52851.cpp:8:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:17:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev.hpp:5:
## /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'static' function 'set_zero_all_adjoints' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
## static void set_zero_all_adjoints() {
## ^
## In file included from file78354a52851.cpp:8:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:21:
## /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/io/dump.hpp:26:14: warning: function 'product' is not needed and will not be emitted [-Wunneeded-internal-declaration]
## size_t product(std::vector<size_t> dims) {
## ^
## 2 warnings generated.
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 1).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.020607 seconds (Warm-up)
## # 0.197304 seconds (Sampling)
## # 0.217911 seconds (Total)
##
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 2).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.021485 seconds (Warm-up)
## # 0.163027 seconds (Sampling)
## # 0.184512 seconds (Total)
##
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 3).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.017467 seconds (Warm-up)
## # 0.120962 seconds (Sampling)
## # 0.138429 seconds (Total)
fit2
## Inference for Stan model: stan_code.
## 3 chains, each with iter=10000; warmup=1000; thin=10;
## post-warmup draws per chain=900, total post-warmup draws=2700.
##
## mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
## mu 3.16 0.00 0.05 3.05 3.12 3.16 3.20 3.27 2675 1
## sigmaSq 0.32 0.00 0.04 0.25 0.29 0.32 0.35 0.42 2669 1
## sigma 0.57 0.00 0.04 0.50 0.54 0.57 0.59 0.65 2661 1
## lp__ 7.17 0.02 0.94 4.73 6.79 7.46 7.84 8.09 2700 1
##
## Samples were drawn using NUTS(diag_e) at Mon Feb 23 12:57:11 2015.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).
infants_dat$alpha <- 2; infants_dat$beta <- 2
fit3 <- stan(model_code = stan_code, data = infants_dat,
iter = 10^4, warmup = 10^3, chains = 3, thin = 10)
##
## TRANSLATING MODEL 'stan_code' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'stan_code' NOW.
## In file included from file78369759e64.cpp:8:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:17:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev.hpp:5:
## /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'static' function 'set_zero_all_adjoints' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
## static void set_zero_all_adjoints() {
## ^
## In file included from file78369759e64.cpp:8:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:21:
## /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/io/dump.hpp:26:14: warning: function 'product' is not needed and will not be emitted [-Wunneeded-internal-declaration]
## size_t product(std::vector<size_t> dims) {
## ^
## 2 warnings generated.
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 1).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.016605 seconds (Warm-up)
## # 0.129159 seconds (Sampling)
## # 0.145764 seconds (Total)
##
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 2).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.013083 seconds (Warm-up)
## # 0.100221 seconds (Sampling)
## # 0.113304 seconds (Total)
##
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 3).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.013287 seconds (Warm-up)
## # 0.131529 seconds (Sampling)
## # 0.144816 seconds (Total)
fit3
## Inference for Stan model: stan_code.
## 3 chains, each with iter=10000; warmup=1000; thin=10;
## post-warmup draws per chain=900, total post-warmup draws=2700.
##
## mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
## mu 3.16 0.00 0.06 3.05 3.12 3.16 3.20 3.28 2470 1
## sigmaSq 0.34 0.00 0.05 0.26 0.31 0.34 0.37 0.45 2177 1
## sigma 0.58 0.00 0.04 0.51 0.56 0.58 0.61 0.67 2194 1
## lp__ 4.04 0.02 1.01 1.36 3.66 4.34 4.76 5.01 2543 1
##
## Samples were drawn using NUTS(diag_e) at Mon Feb 23 12:57:44 2015.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).
infants_dat$alpha <- 2; infants_dat$beta <- 5
fit4 <- stan(model_code = stan_code, data = infants_dat,
iter = 10^4, warmup = 10^3, chains = 3, thin = 10)
##
## TRANSLATING MODEL 'stan_code' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'stan_code' NOW.
## In file included from file7832313f925.cpp:8:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:17:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev.hpp:5:
## /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'static' function 'set_zero_all_adjoints' declared in header file should be declared 'static inline' [-Wunneeded-internal-declaration]
## static void set_zero_all_adjoints() {
## ^
## In file included from file7832313f925.cpp:8:
## In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/model/model_header.hpp:21:
## /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rstan/include//stansrc/stan/io/dump.hpp:26:14: warning: function 'product' is not needed and will not be emitted [-Wunneeded-internal-declaration]
## size_t product(std::vector<size_t> dims) {
## ^
## 2 warnings generated.
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 1).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.015294 seconds (Warm-up)
## # 0.163807 seconds (Sampling)
## # 0.179101 seconds (Total)
##
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 2).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.021897 seconds (Warm-up)
## # 0.174482 seconds (Sampling)
## # 0.196379 seconds (Total)
##
##
## SAMPLING FOR MODEL 'stan_code' NOW (CHAIN 3).
##
## Iteration: 1 / 10000 [ 0%] (Warmup)
## Iteration: 1000 / 10000 [ 10%] (Warmup)
## Iteration: 1001 / 10000 [ 10%] (Sampling)
## Iteration: 2000 / 10000 [ 20%] (Sampling)
## Iteration: 3000 / 10000 [ 30%] (Sampling)
## Iteration: 4000 / 10000 [ 40%] (Sampling)
## Iteration: 5000 / 10000 [ 50%] (Sampling)
## Iteration: 6000 / 10000 [ 60%] (Sampling)
## Iteration: 7000 / 10000 [ 70%] (Sampling)
## Iteration: 8000 / 10000 [ 80%] (Sampling)
## Iteration: 9000 / 10000 [ 90%] (Sampling)
## Iteration: 10000 / 10000 [100%] (Sampling)
## # Elapsed Time: 0.019637 seconds (Warm-up)
## # 0.15379 seconds (Sampling)
## # 0.173427 seconds (Total)
fit4
## Inference for Stan model: stan_code.
## 3 chains, each with iter=10000; warmup=1000; thin=10;
## post-warmup draws per chain=900, total post-warmup draws=2700.
##
## mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
## mu 3.16 0.00 0.06 3.04 3.12 3.16 3.20 3.28 2637 1
## sigmaSq 0.40 0.00 0.06 0.31 0.36 0.40 0.44 0.52 2700 1
## sigma 0.63 0.00 0.04 0.56 0.60 0.63 0.66 0.72 2700 1
## lp__ -4.23 0.02 0.95 -6.66 -4.59 -3.95 -3.56 -3.28 2409 1
##
## Samples were drawn using NUTS(diag_e) at Mon Feb 23 12:58:15 2015.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).