bn_to_adjmatrix: Convert a bn object to an adjacency matrix

Description Usage Arguments Value See Also Examples

View source: R/bn_to_adjmatrix.R

Description

bn_to_adjmatrix takes as input a bn object and converts it to an adjacency matrix.

Usage

1

Arguments

bn_obj

An object of class bn.

Value

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.

See Also

dagitty_to_adjmatrix and adjmatrix_to_dagitty

Examples

 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))

IyarLin/orientDAG documentation built on Jan. 23, 2020, 3:43 a.m.