datasim_make | R Documentation |
Construct and modify data simulations
datasim_make(...)
datasim_to_igraph(sim, report_hidden = FALSE)
datasim_intervene(sim, ...)
sim |
The data simulation object to be modified. |
If | |
... |
Descriptions of the nodes in the simulation, written in assignment form. See details. |
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.
an object of class "datasim". Internally, this is a list of the R assignment expressions used when running the simulation.
Simple_sim <- datasim_make(x <- rnorm(n, sd=2), y <- 3*x + rnorm(n))
Simple_sim |> datasim_run(n = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.