dag_dist: Calculate distance measure between true and estimated DAGs

Description Usage Arguments Details Value Examples

View source: R/dag_dist.R

Description

dag_dist calculates a user specified distance measure between a supplied true DAG and an estimated DAG

Usage

1
dag_dist(true_dag_adjmatrix, estimated_dag_adjmatrix, distance_measure)

Arguments

true_dag_adjmatrix

An adjacency matrix of the true DAG

estimated_dag_adjmatrix

An adjacency matrix of the estimated DAG

distance_measure

One of: 'edge', 'hamming' or 'sid'

Details

The 'edge' distance counts the number of edges present in the true DAG and missing in the estimated DAG, as well as the number of edges present in the estimated DAG and missing in the drue DAG. For details on the 'hamming' option see hammingDist and for 'sid' see structIntervDist

Value

The distance between true and estimated DAGs

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
library(orientDAG)
library(dagitty)

true_dag <- dagitty("dag {
  ageGroup [pos=\"0,0\"]
  vocab [pos=\"1,-1\"]
  nativeBorn [pos=\"2,-2\"]
  educ [pos=\"3,-1\"]
  gender [pos=\"4,0\"]
  nativeBorn -> educ
  nativeBorn -> vocab
  educ -> vocab
  gender -> educ
  ageGroup -> vocab
}")

estimated_dag <- dagitty("dag {
  ageGroup [pos=\"0,0\"]
  vocab [pos=\"1,-1\"]
  nativeBorn [pos=\"2,-2\"]
  educ [pos=\"3,-1\"]
  gender [pos=\"4,0\"]
  gender -> ageGroup
  nativeBorn -> vocab
  educ -> vocab
  educ -> gender
  ageGroup -> vocab
}")


par(mfrow = c(2, 1))
plot(true_dag)
text(0.3, 1.3, "true", cex = 2, col = "red")
plot(estimated_dag)
text(0.3, 1.3, "estimated", cex = 2, col = "red")

# edge distance: number of edges present in the true DAG
# and missing in the estimated DAG
## this won't work: dag_dist(true_dag, estimated_dag)
## Need to convert to adjacency matrices first
true_dag_adjmatrix <- dagitty_to_adjmatrix(true_dag)
estimated_dag_adjmatrix <- dagitty_to_adjmatrix(estimated_dag)

dag_dist(
  true_dag_adjmatrix = true_dag_adjmatrix,
  estimated_dag_adjmatrix = estimated_dag_adjmatrix,
  distance_measure = "edge"
)

# Hamming distance: counts the number of edges
# in which the graphs do not coincide (including edge direction)

dag_dist(
  true_dag_adjmatrix = true_dag_adjmatrix,
  estimated_dag_adjmatrix = estimated_dag_adjmatrix,
  distance_measure = "hamming"
)

# Structural intervention distance: number of wrongly estimated adjustment sets
sid <- dag_dist(
  true_dag_adjmatrix = true_dag_adjmatrix,
  estimated_dag_adjmatrix = estimated_dag_adjmatrix,
  distance_measure = "sid"
)

print(sid)
# The fraction of wrongly estimated adjustment sets out of all possible
# treatment-exposure pairs is:
number_of_nodes <- length(names(true_dag))
print(sid / (number_of_nodes * (number_of_nodes - 1)))

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