Rでの実行
#set to dir which contains source file
STAN_HOME<-<STAN_HOME>
dirpath<-paste0(STAN_HOME, path_to_dir)
#load data to list:dat
データはリス
source(paste0(dirpath, "/rats.data.R"))
ト形式でStan
dat<-list(y=y, x=x, xbar=xbar, N=N, T=T)
に渡せる。
#fit1:to simulate the model as one liner
fit1 <- stan(file = paste0(dirpath, "/rats.stan"), data = dat,
iter = 1000, chains = 4)
apply(extract(fit1)$alpha,2, median)
Stanfitクラス、Stanでの実行結果が返される
前回のモデルを利用
Once a model is fitted, we can use the fitted
result as an input to fit the model with other
data or settings. This would save us time of
compiling the C++ code for the model
https://code.google.com/p/stan/wiki/RStanGettingStarted
#fit again using the previous fit result
fit3<-stan(fit=fit1, data = dat, iter = 400, chains = 4)