Skip to content

Commit 7c5a66a

Browse files
committed
Rel 0.1.0
1 parent 1419faf commit 7c5a66a

9 files changed

Lines changed: 268 additions & 0 deletions

test/runtests.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,54 @@ end
3232
@test d_separation(dag, :x, [:v]; cset=:u, debug=false) == false
3333
@test d_separation(dag, [:x], :v; cset=:s1, debug=false) == false
3434

35+
include("test_descendents_02.jl")
36+
@test d_separation(dag, :k1, :v, cset=[:x1]) == true
37+
@test d_separation(dag, :k1, :v, cset=[:w]) == true
38+
@test d_separation(dag, :k1, :x1, cset=[:w]) == true
39+
@test d_separation(dag, :k1, :x2, cset=[:v]) == true
40+
@test d_separation(dag, :k1, :x2, cset=[:x1]) == true
41+
@test d_separation(dag, :k1, :x2, cset=[:w]) == true
42+
@test d_separation(dag, :k1, :x3, cset=[:w]) == true
43+
@test d_separation(dag, :k1, :y, cset=[:k2, :x2, :x3]) == true
44+
@test d_separation(dag, :k1, :y, cset=[:k2, :v, :x3]) == true
45+
@test d_separation(dag, :k1, :y, cset=[:k2, :x1, :x3]) == true
46+
@test d_separation(dag, :k1, :y, cset=[:k2, :w]) == true
47+
@test d_separation(dag, :k2, :v, cset=[:x1]) == true
48+
@test d_separation(dag, :k2, :v, cset=[:w]) == true
49+
@test d_separation(dag, :k2, :v, cset=[:k1]) == true
50+
@test d_separation(dag, :k2, :w, cset=[:k1]) == true
51+
@test d_separation(dag, :k2, :x1, cset=[:w]) == true
52+
@test d_separation(dag, :k2, :x1, cset=[:k1]) == true
53+
@test d_separation(dag, :k2, :x2, cset=[:v]) == true
54+
@test d_separation(dag, :k2, :x2, cset=[:x1]) == true
55+
@test d_separation(dag, :k2, :x2, cset=[:w]) == true
56+
@test d_separation(dag, :k2, :x2, cset=[:k1]) == true
57+
@test d_separation(dag, :k2, :x3, cset=[:w]) == true
58+
@test d_separation(dag, :k2, :x3, cset=[:k1]) == true
59+
@test d_separation(dag, :v, :w; cset=:x1) == true
60+
@test d_separation(dag, :v, :x3) == true
61+
@test d_separation(dag, :v, :y; cset=[:k2, :x2, :x3]) == true
62+
@test d_separation(dag, :v, :y; cset=[:k1, :x2, :x3]) == true
63+
@test d_separation(dag, :v, :y; cset=[:w, :x2, :x3]) == true
64+
@test d_separation(dag, :v, :y; cset=[:x2, :x1]) == true
65+
@test d_separation(dag, :w, :x2; cset=[:v]) == true
66+
@test d_separation(dag, :w, :x2; cset=[:x1]) == true
67+
@test d_separation(dag, :w, :y; cset=[:k2, :x2, :x3]) == true
68+
@test d_separation(dag, :w, :y; cset=[:k2, :v, :x3]) == true
69+
@test d_separation(dag, :w, :y; cset=[:k1, :x2, :x3]) == true
70+
@test d_separation(dag, :w, :y; cset=[:k1, :v, :x3]) == true
71+
@test d_separation(dag, :w, :y; cset=[:k1, :x1, :x3]) == true
72+
@test d_separation(dag, :w, :y; cset=[:k2, :x2, :x3]) == true
73+
@test d_separation(dag, :x1, :x2; cset=[:v]) == true
74+
@test d_separation(dag, :x1, :x3) == true
75+
@test d_separation(dag, :x1, :y; cset=[:k2, :x2, :x3]) == true
76+
@test d_separation(dag, :x1, :y; cset=[:k1, :x2, :x3]) == true
77+
@test d_separation(dag, :x1, :y; cset=[:w, :x2, :x3]) == true
78+
@test d_separation(dag, :x1, :y; cset=[:k2, :v, :x3]) == true
79+
@test d_separation(dag, :x1, :y; cset=[:k1, :v, :x3]) == true
80+
@test d_separation(dag, :x1, :y; cset=[:v, :w, :x3]) == true
81+
@test d_separation(dag, :x2, :x3) == true
82+
3583
end
3684

3785
@testset "Methods" begin

test/test_adjustment_sets_02.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using StructuralCausalModels, Test
2+
3+
d_str = "dag{k1 -> k2;k2 -> y;v -> x2;w -> k1;x1 -> v;x1 -> w;x2 -> y;x3 -> w;x3 -> y}"
4+
5+
dag = DAG("test_desc", d_str)
6+
7+
to_dagitty(dag) |> display
8+
9+
fname = joinpath(ProjDir, "test_descendents_03.dot")
10+
to_graphviz(dag, fname)
11+
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
12+
13+
display(dag)
14+
display(dag.a)
15+
println(dag.a[:x1, :w])
16+
println(dag.e[:x1, :w])
17+
println()
18+
19+
bs = basis_set(dag)
20+
bs |> display
21+
22+
@show adjustment_sets(dag, :x2, :y)

test/test_descendents.dot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
digraph test_desc {
2+
x1 -> v;
3+
x1 -> w;
4+
v -> x2;
5+
x2 -> y;
6+
x3 -> w;
7+
x3 -> y;
8+
w -> k1;
9+
k1 -> k2;
10+
k2 -> y;
11+
}

test/test_descendents_01.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using StructuralCausalModels
2+
3+
d_str = "DAG(u ~ x + w, x ~ v + z, y ~ v, s1 ~ u, w ~ y, k ~ y, s2 ~ w + s3 + k, s3 ~ s1)"
4+
5+
dag = DAG("test_desc", d_str)
6+
7+
to_dagitty(dag) |> display
8+
9+
fname = joinpath(ProjDir, "test_descendents_01.dot")
10+
to_graphviz(dag, fname)
11+
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
12+
13+
display(dag)
14+
display(dag.a)
15+
println(dag.a[:x, :u])
16+
println(dag.e[:x, :u])
17+
println()
18+
19+
@show d_separation(dag, :x, :w)
20+
@show d_separation(dag, :x, :w; cset=:v)
21+
@show d_separation(dag, :x, :w; cset=:y)
22+
@show d_separation(dag, :x, :v; cset=:s3)
23+
println()
24+
25+
@show adjustment_sets(dag, :x, :w)
26+
@show adjustment_sets(dag, :x, :s1)
27+
@show adjustment_sets(dag, :x, :s2)
28+
@show adjustment_sets(dag, :u, :k)
29+
@show adjustment_sets(dag, :y, :s2)

test/test_descendents_02.dot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
digraph test_desc {
2+
x1 -> v;
3+
x1 -> w;
4+
v -> x2;
5+
x2 -> y;
6+
x3 -> w;
7+
x3 -> y;
8+
w -> k1;
9+
k1 -> k2;
10+
k2 -> y;
11+
}

test/test_descendents_02.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using StructuralCausalModels, Test
2+
3+
d_str = "dag{k1 -> k2;k2 -> y;v -> x2;w -> k1;x1 -> v;x1 -> w;x2 -> y;x3 -> w;x3 -> y}"
4+
5+
dag = DAG("test_desc", d_str)
6+
7+
dagitty_str = to_dagitty(dag)
8+
9+
fname = joinpath(ProjDir, "test_descendents_02.dot")
10+
to_graphviz(dag, fname)
11+
#Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
12+
13+
bs = basis_set(dag)

test/test_descendents_03.dot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
digraph test_desc {
2+
x1 -> v;
3+
x1 -> w;
4+
v -> x2;
5+
x2 -> y;
6+
x3 -> w;
7+
x3 -> y;
8+
w -> k1;
9+
k1 -> k2;
10+
k2 -> y;
11+
}

test/test_descendents_03.jl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using StructuralCausalModels, Test
2+
3+
d_str = "dag{k1 -> k2;k2 -> y;v -> x2;w -> k1;x1 -> v;x1 -> w;x2 -> y;x3 -> w;x3 -> y}"
4+
5+
dag = DAG("test_desc", d_str)
6+
7+
to_dagitty(dag) |> display
8+
9+
fname = joinpath(ProjDir, "test_descendents_03.dot")
10+
to_graphviz(dag, fname)
11+
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
12+
13+
bs = basis_set(dag)
14+
bs |> display
15+
16+
@show d_separation(dag, :x1, :x2; cset=[:v])
17+
@show d_separation(dag, :x1, :x3)
18+
@show d_separation(dag, :x1, :k1; cset=[:w])
19+
@show d_separation(dag, :x1, :k2; cset=[:x2])
20+
@show d_separation(dag, :x1, :y; cset=[:x2, :x3, :k2])
21+
22+
bs[5] |> display
23+
24+
@show d_separation(dag, :k1, :v, cset=[:x1])
25+
@show d_separation(dag, :k1, :v, cset=[:w])
26+
@show d_separation(dag, :k1, :x1, cset=[:w])
27+
@show d_separation(dag, :k1, :x2, cset=[:v])
28+
@show d_separation(dag, :k1, :x2, cset=[:x1])
29+
@show d_separation(dag, :k1, :x2, cset=[:w])
30+
@show d_separation(dag, :k1, :x3, cset=[:w])
31+
@show d_separation(dag, :k1, :y, cset=[:k2, :x2, :x3])
32+
@show d_separation(dag, :k1, :y, cset=[:k2, :v, :x3])
33+
@show d_separation(dag, :k1, :y, cset=[:k2, :x1, :x3])
34+
@show d_separation(dag, :k1, :y, cset=[:k2, :w])
35+
println()
36+
37+
@show d_separation(dag, :k2, :v, cset=[:x1])
38+
@show d_separation(dag, :k2, :v, cset=[:w])
39+
@show d_separation(dag, :k2, :v, cset=[:k1])
40+
@show d_separation(dag, :k2, :w, cset=[:k1])
41+
@show d_separation(dag, :k2, :x1, cset=[:w])
42+
@show d_separation(dag, :k2, :x1, cset=[:k1])
43+
@show d_separation(dag, :k2, :x2, cset=[:v])
44+
@show d_separation(dag, :k2, :x2, cset=[:x1])
45+
@show d_separation(dag, :k2, :x2, cset=[:w])
46+
@show d_separation(dag, :k2, :x2, cset=[:k1])
47+
@show d_separation(dag, :k2, :x3, cset=[:w])
48+
@show d_separation(dag, :k2, :x3, cset=[:k1])
49+
println()
50+
51+
@show d_separation(dag, :v, :w; cset=:x1)
52+
@show d_separation(dag, :v, :x3)
53+
@show d_separation(dag, :v, :y; cset=[:k2, :x2, :x3])
54+
@show d_separation(dag, :v, :y; cset=[:k1, :x2, :x3])
55+
@show d_separation(dag, :v, :y; cset=[:w, :x2, :x3])
56+
@show d_separation(dag, :v, :y; cset=[:x2, :x1])
57+
println()
58+
59+
@show d_separation(dag, :w, :x2; cset=[:v])
60+
@show d_separation(dag, :w, :x2; cset=[:x1])
61+
@show d_separation(dag, :w, :y; cset=[:k2, :x2, :x3])
62+
@show d_separation(dag, :w, :y; cset=[:k2, :v, :x3])
63+
@show d_separation(dag, :w, :y; cset=[:k1, :x2, :x3])
64+
@show d_separation(dag, :w, :y; cset=[:k1, :v, :x3])
65+
@show d_separation(dag, :w, :y; cset=[:k1, :x1, :x3])
66+
@show d_separation(dag, :w, :y; cset=[:k2, :x2, :x3])
67+
println()
68+
69+
@show d_separation(dag, :x1, :y; cset=[:k1, :v, :x3])
70+
@show d_separation(dag, :x1, :y; cset=[:v, :w, :x3])
71+
println()
72+
73+
@show d_separation(dag, :x2, :x3)
74+
println()
75+
76+
@show adjustment_sets(dag, :x2, :y)

test/test_split_basis_set_01.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using StructuralCausalModels, Test
2+
3+
ProjDir = @__DIR__
4+
5+
d_str = "dag{k1 -> k2;k2 -> y;v -> x2;w -> k1;x1 -> v;x1 -> w;x2 -> y;x3 -> w;x3 -> y}"
6+
7+
dag = DAG("test_desc", d_str)
8+
9+
dagitty_str = to_dagitty(dag)
10+
11+
fname = joinpath(ProjDir, "test_descendents_03.dot")
12+
to_graphviz(dag, fname)
13+
#Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
14+
15+
bs = basis_set(dag)
16+
println()
17+
18+
bs[6] |> display
19+
@show d_separation(dag, :v, :x3; cset=[:x1])
20+
@show d_separation(dag, :v, :x3)
21+
@show d_separation(dag, :x1, :x3; cset=[:x1]) # <====
22+
println()
23+
24+
bs[7] |> display
25+
@show d_separation(dag, :v, :w; cset=[:x1, :x3])
26+
@show d_separation(dag, :v, :w; cset=[:x1])
27+
@show d_separation(dag, :v, :w; cset=[:x3])
28+
println()
29+
30+
bs[8] |> display
31+
@show d_separation(dag, :v, :k1; cset=[:x1, :w])
32+
@show d_separation(dag, :v, :k1; cset=[:x1])
33+
@show d_separation(dag, :v, :k1; cset=[:w])
34+
println()
35+
36+
bs[9] |> display
37+
@show d_separation(dag, :v, :y; cset=[:x1, :x2, :x3, :k2])
38+
@show d_separation(dag, :v, :y; cset=[:k2, :x2, :x3])
39+
@show d_separation(dag, :v, :y; cset=[:k1, :x2, :x3])
40+
@show d_separation(dag, :v, :y; cset=[:w, :x2, :x3])
41+
@show d_separation(dag, :v, :y; cset=[:x1, :x2])
42+
println()
43+
44+
bs[10] |> display
45+
@show d_separation(dag, :x2, :x3; cset=[:v])
46+
@show d_separation(dag, :x2, :x3)
47+
println()

0 commit comments

Comments
 (0)