adjmatrix_to_dagitty: Convert an adjacency matrix to a dagitty object

Description Usage Arguments Value See Also Examples

View source: R/adjmatrix_to_dagitty.R

Description

adjmatrix_to_dagitty takes as input an adjacency matrix and converts it to a dagitty object.

Usage

1

Arguments

adjmatrix

A named adjacency matrix where a 1 in the i,j position denotes an edge from node i to node j. The matrix row and column names should denote the node names.

Value

A dagitty object with the same edge orientations.

See Also

dagitty_to_adjmatrix and bn_to_adjmatrix

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.