dag_node {causact}R Documentation

Add a node to an existing causact_graph object


The graph object should be of class causact_graph and created using dag_create().


  descr = as.character(NA),
  label = as.character(NA),
  rhs = NA,
  child = as.character(NA),
  data = NULL,
  obs = FALSE,
  keepAsDF = FALSE,
  extract = as.logical(NA),
  dec = FALSE,
  det = FALSE



a graph object of class causact_graph. An initial object gets created using dag_create().


a longer more descriptive character label for the node.


a shorter character label for referencing the node (e.g. "X","beta").


either a greta distribution such as uniform, normal, lognormal, bernoulli, etc. or an R expression. Greta distribution arguments are optional. Valid values include normal(mu,sigma),greta::normal, normal, and normal(6,2). R computation/expression examples include alpha+beta*x or ilogit(alpha + gamma + beta). If a distribution is given, this is a random/stochastic node, if a formula is given it is a deterministic node once given the values of its parents. Quotes should not be used as all function/computations should consist of R objects, functions, and constants.


an optional character vector of existing node labels. Directed edges from the newly created node to the supplied nodes will be created.


a vector or data frame (with observations in rows and variables in columns).


a logical value indicating whether the node is observed. Assumed to be TRUE when data argument is given.


a logical value indicating whether the data argument should be split into one random varaible node per column or kept together as a random matrix for matrix computation. Defaults to creating one node per column of the data frame.


a logical value. When TRUE, child nodes will try to extract an indexed value from this node. When FALSE, the entire random object (e.g. scalar, vector, matrix) is passed to children nodes. Only use this argument when overriding default behavior seen using dag_render().


a logical value indicating whether the node is a decision node. Used to show nodes as rectangles instead of ovals when using dag_render().


a logical value indicating whether the node is a deterministic function of its parents Used to draw a double-line (i.e. peripheries = 2) around a shape when using dag_render(). Assumed to be TRUE when rhs is a formula.


a graph object of class causact_graph with an additional node(s).


# Create an empty graph and add 2 nodes by using
# the `dag_node()` function twice
graph2 = dag_create() %>%
  dag_node("Get Card","y",
         rhs = bernoulli(theta),
         data = carModelDF$getCard) %>%
  dag_node(descr = "Card Probability by Car",label = "theta",
           rhs = beta(2,2),
           child = "y")
graph2 %>% dag_render()

# The Eight Schools Example from Gelman et al.:

schools_dat <- data.frame(y = c(28,  8, -3,  7, -1,  1, 18, 12),
sigma = c(15, 10, 16, 11,  9, 11, 10, 18), schoolName = paste0("School",1:8))

graph = dag_create() %>%
  dag_node("Treatment Effect","y",
           rhs = normal(theta, sigma),
           data = schools_dat$y) %>%
  dag_node("Std Error of Effect Estimates","sigma",
           data = schools_dat$sigma,
           child = "y") %>%
  dag_node("Exp. Treatment Effect","theta",
           child = "y",
           rhs = avgEffect + schoolEffect) %>%
  dag_node("Pop Treatment Effect","avgEffect",
           child = "theta",
           rhs = normal(0,30)) %>%
  dag_node("School Level Effects","schoolEffect",
           rhs = normal(0,30),
           child = "theta") %>%
  dag_plate("Observation","i",nodeLabels = c("sigma","y","theta")) %>%
  dag_plate("School Name","school",
            nodeLabels = "schoolEffect",
            data = schools_dat$schoolName,
            addDataNode = TRUE)

graph %>% dag_render()
## Not run: 
# below requires Tensorflow installation
graph %>% dag_greta(mcmc=TRUE)
tidyDrawsDF %>% dagp_plot()

## End(Not run)

[Package causact version 0.4.0 Index]