6 Bayesian Networks: With Examples in R
bnlearn provides many other functions to investigate and manipulate bn
objects. For a comprehensive overview, we refer the reader to the documenta-
tion included in the package. Two basic examples are nodes and arcs.
> nodes(dag)
[1] "A" "S" "E" "O" "R" "T"
> arcs(dag)
from to
[1,] "A" "E"
[2,] "S" "E"
[3,] "E" "O"
[4,] "E" "R"
[5,] "O" "T"
[6,] "R" "T"
The latter function also provides a way to add arcs to a DAG that is faster
than setting them one at a time. Obviously, the approach we used above is too
cumbersome for large DAGs. Instead, we can create a matrix with the same
structure as that returned by arcs and set the whole arc set at once.
> dag2 <- empty.graph(nodes = c("A", "S", "E", "O", "R", "T"))
> arc.set