dag_node {causact} | R Documentation |
Add a node to an existing causact_graph
object
Description
Add a node to an existing causact_graph
object. The graph object should be of class causact_graph
and created using dag_create()
.
Usage
dag_node(
graph,
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
)
Arguments
graph |
a graph object of class |
descr |
a longer more descriptive character label for the node. |
label |
a shorter character label for referencing the node (e.g. "X","beta"). Labels with |
rhs |
either a distribution such as |
child |
an optional character vector of existing node labels. Directed edges from the newly created node to the supplied nodes will be created. |
data |
a vector or data frame (with observations in rows and variables in columns). |
obs |
a logical value indicating whether the node is observed. Assumed to be |
keepAsDF |
a logical value indicating whether the |
extract |
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 |
dec |
a logical value indicating whether the node is a decision node. Used to show nodes as rectangles instead of ovals when using |
det |
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 |
Value
a graph object of class causact_graph
with an additional node(s).
Examples
# 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
drawsDF = graph %>% dag_numpyro(mcmc=TRUE)
tidyDrawsDF %>% dagp_plot()
## End(Not run)