8.3 Program block: data
The rest of this chapter will lay out the details of each block in
order, starting with the data
block in this section.
Variable reads and transformations
The data
block is for the declaration of variables that are
read in as data. With the current model executable, each Markov chain
of draws will be executed in a different process, and each such
process will read the data exactly once.13
Data variables are not transformed in any way. The format for data files or data in memory depends on the interface; see the user’s guides and interface documentation for PyStan, RStan, and CmdStan for details.
Statements
The data
block does not allow statements.
Variable constraint checking
Each variable’s value is validated against its declaration as it is
read. For example, if a variable sigma
is declared as
real<lower=0>
, then trying to assign it a negative value will raise
an error. As a result, data type errors will be caught as early as
possible. Similarly, attempts to provide data of the wrong size for a
compound data structure will also raise an error.
With multiple threads, or even running chains sequentially in a single thread, data could be read only once per set of chains. Stan was designed to be thread safe and future versions will provide a multithreading option for Markov chains.↩︎