Description Usage Arguments Value See Also Examples
View source: R/bn_to_adjmatrix.R
bn_to_adjmatrix
takes as
input a bn
object and converts it to
an adjacency matrix.
1 | bn_to_adjmatrix(bn_obj)
|
bn_obj |
An object of class |
A named adjacency matrix where a 1 in the i,j
position denotes an arrow from node i
to node j
.
The matrix row and column names denote the node names.
dagitty_to_adjmatrix
and adjmatrix_to_dagitty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | library(orientDAG)
library(dagitty)
library(bnlearn)
library(igraph)
g <- dagitty("dag {
bn [pos=\"0,0\"]
dagitty [pos=\"0.5,-1\"]
adjmatrix [pos=\"1,0\"]
adjmatrix -> dagitty
dagitty -> adjmatrix
bn -> adjmatrix
}")
# Below we can see the conversion directions implemented in this package:
plot(g)
# dagitty -> adjmatrix
adjmatrix <- dagitty_to_adjmatrix(g)
print(adjmatrix)
# adjmatrix -> dagitty
dagitty_obj <- adjmatrix_to_dagitty(adjmatrix)
plot(graphLayout(dagitty_obj))
# bn -> adjmatrix
bn_obj <- empty.graph(c("adjmatrix", "bn", "dagitty"))
amat(bn_obj) <- adjmatrix
plot(bn_obj)
adjmatrix <- bn_to_adjmatrix(bn_obj)
plot(graph_from_adjacency_matrix(adjmatrix))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.