Bayesian inference often requires many iterations of model fitting, data replication, and model checking, before a suitable set of inferences is reached. It can be cumbersome to try to save all of the model forms and input data files for each iteration, and often researchers find themselves drowning in a sea of Stan files, MCMC traces, and datasets.
Further developments of the package will attempt to address the larger problem of what Andrew Gelman calls the network of models, which is a philosophical attempt at conveying the idea of a machine-aided inference workflow. For now, we stick with the general case, and save everything seperately.
For this inference problem, the {r} save_fit
function can be used to record a simple workflow without having to resort to saving multuple stan files.
library(rstan) options(mc.cores = 2) rstan_options(auto_write = TRUE) y = rnorm(10, 1, 1.2) data = list( n = length(y), y = y ) file = '~/Documents/stansave/vignettes/gaussian.stan' fit = stan(file, data = data, chains = 2) save_fit(file, fit, data)
For reference, gaussian.stan is written as ```{stan, output.var = "gaussian"} data { int n; real y[n]; }
parameters {
real mu;
real
model { y ~ normal(mu, sigma); } ```
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.