Skip to contents

This function allows users to add DAG.node objects created using the node or node_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.

Usage

add_node(dag, node)

# S3 method for class 'DAG'
object_1 + object_2

Arguments

dag

A DAG object created using the empty_dag function.

node

A DAG.node object created using the node function or node_td function.

object_1

Either a DAG object or a DAG.node object. The order of the objects does not change the result.

object_2

See argument object_1.

Details

The two ways of adding a node 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.

Value

Returns an DAG object with the DAG.node object added to it.

Author

Robin Denz

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))