Simulations in LSTbook
are first specified by providing the
code for each node (which can be written in terms of the values of other nodes). Once
constructed, data can be extracted from the simulation using datasim_run(n)
or the
generic take_sample(n)
.
Each argument defines one node in the simulation. The argument syntax is unusual, using
assignment. For instance, an argument y <- 3*x + rnorm(n)
defines a node named y
. The R code
on the RHS of the assignment operator (that is, 3*x + rnorm(n)
in the example) will
be used by datasim_run()
to generate the y
variable when the simulation is run. Nodes
defined by previous arguments can be used in the code for later arguments.
Helper functions such as mix_with()
, categorical()
, and several others can be used within
the node to perform complex operations.
Remember to use commas to separate the arguments in the normal way.