dag {cfid} | R Documentation |
Directed Acyclic Graph
Description
Define a directed acyclic graph (DAG) describing the causal model.
Usage
dag(x, u = character(0L))
## S3 method for class 'dag'
print(x, ...)
Arguments
x |
A |
u |
A |
... |
Not used |
Details
The syntax for x
follows the dagitty
package closely for compatibility.
However, not all features of dagitty
graphs are supported.
The resulting adjacency matrix of the definition is checked for cycles.
Directed edges are defined as X -> Y
meaning that there is an edge from
X
to Y
in the graph. Edges can be combined in sequence to create paths
for concise descriptions, for example X -> Y <- Z -> W
.
Unobserved latent confounders are defined using bidirected edges as
X <-> Y
which means that there is an additional variable U[X,Y]
in
the graph, and the edges X <- U[X,Y] -> Y
, respectively.
Different statements in x
can be distinguished from one
another using either semicolons, line breaks, or spaces.
Subgraphs can be defined by enclosing the definition within
curly braces. For example X -> {Y Z}
defines an edge
from X
to both Y
and Z
. Individual statements within a subgraph can be
separated by a comma or semicolon, but this is optional.
Edges can also be defined within subgraphs, and subgraphs can be nested.
For example, X -> {Z -> Y}
is the same definition as
X -> Z; X -> Y; Z -> Y
. Similarly X <-> {Z -> {A B}} -> Y
is the same as
X <-> {Z A B} -> Y; Z -> {A B}
.
Note that in the context of this package, vertex labels will always be
converted into upper case, meaning that typing Z
or z
will
always represent the same variable. This is done to enforce the notation
of counterfactual variables, where capital letters denote variables
and small letters denote their value assignments.
Value
An object of class dag
, which is a square adjacency matrix
with the following attributes:
-
labels
Acharacter
vector (or a list) of vertex labels. -
latent
Alogical
vector indicating latent variables. -
order
Aninteger
vector giving a topological order for the vertices. -
text
Acharacter
string giving representing the DAG. .
Examples
dag("X -> {Y Z} <- W <-> G")
# Subgraphs can appear on both sides of an edge
dag("{X Z} -> {Y W}")
# Semicolons can be used to distinguish individual statements
dag("X -> Z -> Y; X <-> Y")
# Commas can be used to distinguish variables within groups if there
# are no edges within the group
dag("{X, Y, Z} -> W")
# Edges within subgraphs is supported
dag("{X -> Z} -> {Y <-> W}")
# Nested subgraphs are supported
dag("{X -> {Z -> {Y <-> W}}}")
# Line breaks are also supported for statement separation
dag("
Z -> W
X -> Y
")