-
Notifications
You must be signed in to change notification settings - Fork 0
/
d-seperation.qmd
168 lines (134 loc) · 3.68 KB
/
d-seperation.qmd
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
title: "d-seperation"
format: html
editor: visual
---
# D-separation
## Definition
Two variables are said to be d-separated if all paths between them are blocked (otherwise they are d-connected). Two sets of variables are said to be d-separated if each variable in the first set is d-separated from every variable in the second set.
## Rules: When is a path open or blocked?
**1. If there are no variables being conditioned on, a path is blocked if and only if two arrowheads on the path collide at some variable on the path.**
```{r}
library(ggdag)
dag1_confound_ggdag <- dagify(
C ~ A + B
)
# Plot the DAG
ggdag(dag1_confound_ggdag) + theme_dag_blank()
```
### Beispiel:
**D=Drivingskills**\
**A=Alkohol**\
**U=Unfall**
Der Pfad zwischen den Drivingskills und dem Alkoholkonsum ist durch den Collider Unfall blockiert.
```{r}
dag2_confound_ggdag <- dagify(
U ~ D + A
)
# Plot the DAG
ggdag(dag2_confound_ggdag, layout = "circle") + theme_dag_blank()
```
### Regression:
```{r}
# set number of observations
n <- 10000
D <- rnorm(n, 0, 1)
A <- rbinom(n, 1, 0.05)
U <- 0.01 + 0.3*A - 0.1 * D + rnorm(n, 0, 1)
lm(U ~ A + D)
```
**2. Any path that contains a noncollider that has been conditioned on is blocked.**\
The path between A and C is blocked, conditioning on B.
```{r}
dag3_confound_ggdag <- dagify(
C ~ B,
B ~ A,
coords = list(x = c(A = 1, B = 2, C = 3),
y = c(A = 1, B = 1, C = 1))
)
# Plot the DAG
ggdag(dag3_confound_ggdag) + theme_dag_blank()
```
### Beispiel:
**F=Feuer**\
**R=Rauch**\
**A=Alarm**
Feuer und Alarm sind unabhängig, bedingt auf Rauch.
```{r}
dag4_confound_ggdag <- dagify(
A ~ R,
R ~ F,
coords = list(x = c(F = 1, R = 2, A = 3),
y = c(F = 1, R = 1, A = 1))
)
# Plot the DAG
ggdag(dag4_confound_ggdag) + theme_dag_blank()
```
**3. A collider that has been conditioned on does not block a path.** If we condition on C, the path between A and B is not blocked. They are d-connected.
```{r}
dag5_confound_ggdag <- dagify(
C ~ A + B
)
# Plot the DAG
ggdag(dag5_confound_ggdag, layout = "circle") + theme_dag_blank()
```
Durch die Konditionierung auf "Unfall" ist der Pfad zwischen Drivingskills und Alkohol nicht mehr blockiert.
```{r}
dag6_confound_ggdag <- dagify(
U ~ D + A
)
# Plot the DAG
ggdag(dag6_confound_ggdag, layout = "circle") + theme_dag_blank()
```
**4. A collider that has a descendant that has been conditioned on does not block a path.**
```{r}
library(ggdag)
dag7_confound_ggdag <- dagify(
C ~ A + B,
D ~C,
coords = list(x = c(B = 1, C = 2, D = 2, A = 3),
y = c(B = 3, C = 2, D = 1, A = 3))
)
# Plot the DAG
ggdag(dag7_confound_ggdag) + theme_dag_blank()
```
### Beispiel
**Neue Variable S=Schäden am Auto**\
Die Variable "Schäden am Auto" ist ein Nachfolger des Colliders "Unfall". D und A waren d-seperated durch Collider U, aber sind d-connected, sobald wir auf S bedingen.
```{r}
library(ggdag)
dag8_confound_ggdag <- dagify(
U ~ D + A,
S ~ U,
coords = list(x = c(D = 1, U = 2, S = 2, A = 3),
y = c(D = 3, U = 2, S = 1, A = 3))
)
# Plot the DAG
ggdag(dag8_confound_ggdag) + theme_dag_blank()
```
## Excercise
What sets of variables d-seperate the nonadjacent nodes in this DAG?
```{r}
dag9_confound_ggdag <- dagify(
X ~ Z1 + Z3,
Z3 ~ Z1 + Z2,
W ~ X,
Y ~ W + Z2 + Z3,
coords = list(x = c(X = 1, Z1 = 1, Z3 = 2, W = 2, Z2 = 3, Y = 3),
y = c(X = 1, Z1 = 3, Z3 = 2, W = 1, Z2 = 3, Y = 1))
)
# Plot the DAG
ggdag(dag9_confound_ggdag) + theme_dag_blank()
```
Z1 ⊥⊥ Z2\
X ⊥⊥ Y \| W, Z3, Z1\
oder\
X ⊥⊥ Y \| W, Z2, Z3\
X ⊥⊥ Y \| Z1, Z3\
W ⊥⊥ Z2 \| Z1, Z3\
W ⊥⊥ Z2 \| X\
W ⊥⊥ Z3 \| X\
W ⊥⊥ Z1 \| X\
Z1 ⊥⊥ Y \|Z3, X, Z2\
oder\
Z1 ⊥⊥ Y \| Z3, W, Z2