
Add a DAG.node or a DAG.network object to a DAG object
add_node.RdThis function allows users to add DAG.node objects created using the node or node_td function and DAG.network objects created using the network or network_td function to DAG objects created using the empty_dag function, which makes it easy to fully specify a DAG to use in the sim_from_dag function and sim_discrete_time.
Arguments
- dag
A
DAGobject created using theempty_dagfunction.- node
Either a
DAG.nodeobject created using thenodefunction ornode_tdfunction, or aDAG.networkobject created using thenetworkfunction ornetwork_tdfunction.- object_1
Either a
DAGobject, aDAG.nodeobject or aDAG.networkobject. The order of the objects does not change the result.- object_2
See argument
object_1.
Details
The two ways of adding a node or a network to a DAG object are: dag <- add_node(dag, node(...)) and dag <- dag + node(...), which give identical results (note that the ... should be replaced with actual arguments and that the initial dag should be created with a call to empty_dag). See node for more information on how to specify a DAG for use in the sim_from_dag and node_td functions.
Examples
library(simDAG)
## add nodes to DAG using +
dag <- empty_dag() +
node("age", type="rnorm", mean=50, sd=5) +
node("sex", type="rbernoulli", p=0.5) +
node("income", type="gaussian", parents=c("age", "sex"), betas=c(1.1, 0.2),
intercept=-5, error=4)
## add nodes to DAG using add_node()
dag <- empty_dag()
dag <- add_node(dag, node("age", type="rnorm", mean=50, sd=5))