BayES BayES

3.4 Interface to Stan

Stan is another open-source program similar to JAGS and OpenBUGS, but with two important differences (i) the language it uses is slightly more complex, but also more flexible, and (ii) it uses specialized sampling algorithms designed to work efficiently on hierarchical models. No matter these differences, Stan also takes as inputs data and a model specification file (written in Stan’s own language) and draws samples from the posterior distribution of the model’s parameters or latent variables, or maximizes the respective likelihood function.

BayESstan() function provides a convenient interface to Stan, which allows the user to:

The general syntax of the stan() function is the following:4

[<model name> = ] stan( <model specification file> 
        [, "method"="sample"|"variational"|"optimize" ] 
        [, "data"=<list of matrices to pass to Stan> ] 
        [, "inits"=<structure of initial values> ] 
        [, "output"=<file where Stan should store its results> ] 
        [, "diagnostic"=<file where Stan should store results for diagnostics> ] 
        [, "options"=<additional command-line options> ] 
        [, "summarize"=true|false ] 
        [, "diagnose"=true|false ] 
        [, "chains"=<positive integer> ] 
        [, "burnin"=<positive integer> ] 
        [, "draws"=<positive integer> ] 
        [, "thin"=<positive integer> ] 
        [, "seed"=<positive integer> ] 
        [, "refresh"=<positive integer> ] 
        );

where:

PIC The path to the Stan model specification file must not contain any spaces.

As the stan() function executes, Stan attempts to print output on the system’s command console. BayES grabs this output and redirects it to the BayES main console in real time. This output is entirely determined by Stan and it includes information on the model specification file used in the current run, all the options used, any errors or warnings and, most importantly, information on the progress of the algorithm being used. Note that when multiple chains are run in parallel (under Stan’s “sample" method), BayES mutes Stan’s output on the console.

Many of the sample script files in "$BayESHOME/Samples/3JAGSOpenBUGSStan" contain examples of using the stan() function, along with Stan model specification files for simple models. The Stan interface is also accessible from the BayES main menu via Interfaces Stan.

4Arguments inside square brackets are optional. Optional arguments passed to the stan() function can be provided in any order, but always after the mandatory argument (model specification file). Optional arguments always come in pairs (eg. "chains"=1).

Share this content:
Facebook Twitter LinkedIn Email
© 2016–20 Grigorios Emvalomatis