Skip to content

Commit 605ec22

Browse files
committed
Rel 0.1.0
1 parent f874195 commit 605ec22

File tree

9 files changed

+188
-137
lines changed

9 files changed

+188
-137
lines changed

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ edge_matrix(a::NamedArray, inv=false)
5757
indicator_matrix(e::NamedArray)
5858
induced_covariance_graph(d::DAG, sel::Vector{Symbol}, cond::SymbolList; debug=false)
5959
node_edges(p::Path, s::Symbol, l::Symbol)
60-
pcor(u::Vector{Symbol}, S::NamedArray)
60+
pcor(d::DAG, u::SymbolList)
6161
topological_order(a::NamedArray)
6262
topological_sort(a::NamedArray)
6363
transitive_closure(a::NamedArray)

test/runtests.jl

Lines changed: 18 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,32 @@
11
using StructuralCausalModels
22
using Test
33

4-
@testset "DAGs" begin
4+
include("test_dag_formulations.jl")
5+
include("test_set_dag_df.jl")
56

6-
include("test_dag_formulations.jl")
7-
include("test_set_dag_df.jl")
7+
include("test_dagitty_conversion.jl")
8+
include("test_ggm_conversion.jl")
89

9-
end
10-
11-
@testset "DAG conversions" begin
12-
13-
include("test_dagitty_conversion.jl")
14-
include("test_ggm_conversion.jl")
15-
include("test_graphviz_conversions.jl")
16-
17-
end
18-
19-
@testset "d_separation" begin
20-
21-
include("test_d_separation.jl")
22-
@test to_ggm(dag) == "DAG(u ~ x + v, s1 ~ u, w ~ v + y, s2 ~ w)"
23-
@test d_separation(dag, :x, :v; debug=false) == true
24-
@test d_separation(dag, :x, [:v]; cset=:u, debug=false) == false
25-
@test d_separation(dag, [:x], :v; cset=:s1, debug=false) == false
26-
@test d_separation(dag, [:u], [:w]; debug=false) == false
27-
@test d_separation(dag, :u, [:w]; cset=:v, debug=false) == true
28-
@test d_separation(dag, [:x], :y; debug=false) == true
29-
@test d_separation(dag, :x, :y; cset=[:u, :w], debug=false) == false
30-
@test d_separation(dag, :x, :y; cset=[:s1, :s2], debug=false) == false
31-
@test d_separation(dag, :x, :y; cset=[:u, :v, :w], debug=false) == true
32-
@test d_separation(dag, :x, [:v]; cset=:u, debug=false) == false
33-
@test d_separation(dag, [:x], :v; cset=:s1, debug=false) == false
34-
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-
83-
end
84-
85-
@testset "Methods" begin
86-
87-
include("test_sr6_4_3b.jl")
88-
include("test_ag.jl")
89-
90-
end
10+
include("test_graphviz_conversions.jl")
9111

92-
@testset "Adjustment_sets" begin
12+
include("test_basis_set_01.jl")
9313

94-
include("test_open_paths_01.jl")
95-
include("test_open_paths_02.jl")
96-
include("test_open_paths_03.jl")
97-
include("test_open_paths_04.jl")
14+
include("test_d_separation.jl")
9815

99-
end
16+
include("test_descendents_01.jl")
17+
include("test_descendents_02.jl")
18+
include("test_descendents_03.jl")
10019

101-
@testset "SR6.4.2" begin
20+
include("test_sr6_4_3b.jl")
10221

103-
include("test_sr6_4_2.jl")
22+
include("test_ag.jl")
10423

105-
end
24+
include("test_open_paths_01.jl")
25+
include("test_open_paths_02.jl")
26+
include("test_open_paths_03.jl")
27+
include("test_open_paths_04.jl")
10628

107-
@testset "SR6.4.3" begin
29+
include("test_sr6_4_2.jl")
10830

109-
include("test_sr6_4_3.jl")
31+
include("test_sr6_4_3.jl")
11032

111-
end

test/test_basis_set_01.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,26 @@ d_str = "dag{k1 -> k2;k2 -> y;v -> x2;w -> k1;x1 -> v;x1 -> w;x2 -> y;x3 -> w;x3
66

77
dag = DAG("test_desc", d_str)
88

9-
to_dagitty(dag) |> display
9+
to_dagitty(dag)
1010

1111
#=
1212
fname = joinpath(ProjDir, "test_descendents_03.dot")
1313
to_graphviz(dag, fname)
1414
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
1515
=#
1616

17-
display(dag)
18-
1917
bs = basis_set(dag)
20-
bs |> display
18+
19+
@testset "basis_set_01" begin
20+
21+
@test length(bs) == 48
22+
@test bs[18] == [:x2, :w, :v]
23+
@test bs[19] == [:x2, :w, :x1]
24+
@test bs[20] == [:x2, :w, :v, :x1]
25+
@test bs[44] == [:y, :k1, :w, :k2]
26+
@test bs[45] == [:y, :k1, :w, :x2, :k2]
27+
@test bs[46] == [:y, :k1, :w, :x3, :k2]
28+
@test bs[47] == [:y, :k1, :x2, :x3, :k2]
29+
@test bs[48] == [:y, :k1, :w, :x2, :x3, :k2]
30+
31+
end

test/test_d_separation.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,67 @@ d = OrderedDict(
1717

1818
dag = DAG("fig2.6", d);
1919

20+
@testset "d_separation" begin
21+
22+
@test to_ggm(dag) == "DAG(u ~ x + v, s1 ~ u, w ~ v + y, s2 ~ w)"
23+
@test d_separation(dag, :x, :v; debug=false) == true
24+
@test d_separation(dag, :x, [:v]; cset=:u, debug=false) == false
25+
@test d_separation(dag, [:x], :v; cset=:s1, debug=false) == false
26+
@test d_separation(dag, [:u], [:w]; debug=false) == false
27+
@test d_separation(dag, :u, [:w]; cset=:v, debug=false) == true
28+
@test d_separation(dag, [:x], :y; debug=false) == true
29+
@test d_separation(dag, :x, :y; cset=[:u, :w], debug=false) == false
30+
@test d_separation(dag, :x, :y; cset=[:s1, :s2], debug=false) == false
31+
@test d_separation(dag, :x, :y; cset=[:u, :v, :w], debug=false) == true
32+
@test d_separation(dag, :x, [:v]; cset=:u, debug=false) == false
33+
@test d_separation(dag, [:x], :v; cset=:s1, debug=false) == false
34+
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+
83+
end

test/test_descendents_01.jl

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
1-
using StructuralCausalModels
1+
using StructuralCausalModels, Test
22

33
ProjDir = @__DIR__
44

55
d_str = "DAG(u ~ x + w, x ~ v + z, y ~ v, s1 ~ u, w ~ y, k ~ y, s2 ~ w + s3 + k, s3 ~ s1)"
66

77
dag = DAG("test_desc", d_str)
88

9-
to_dagitty(dag) |> display
9+
to_dagitty(dag)
1010

1111
#=
1212
fname = joinpath(ProjDir, "test_descendents_01.dot")
1313
to_graphviz(dag, fname)
1414
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
1515
=#
1616

17-
display(dag)
18-
display(dag.a)
19-
println(dag.a[:x, :u])
20-
println(dag.e[:x, :u])
21-
println()
22-
2317
bs = basis_set(dag)
24-
display(bs)
25-
2618
as = adjustment_sets(dag, :u, :s2)
27-
display(as)
19+
20+
@testset "Test_descendents_01" begin
21+
22+
@test dag.a[:x, :u] == 0
23+
@test dag.e[:x, :u] == 1
24+
@test length(bs) == 83
25+
@test bs[70] == [:y, :s1, :u]
26+
@test bs[71] == [:y, :s1, :v, :u]
27+
@test bs[81] == [:z, :k, :y]
28+
@test bs[82] == [:z, :s2, :k, :w, :s3]
29+
@test bs[83] == [:z, :s3, :s1]
30+
31+
end
32+
33+
@testset "Adjustment_sets" begin
34+
35+
@test as[1] == [:x, :w]
36+
@test as[2] == [:v, :w]
37+
@test as[3] == [:y, :w]
38+
@test as[4] == [:w, :k]
39+
40+
end

test/test_descendents_02.jl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,26 @@ Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
1515
=#
1616

1717
bs = basis_set(dag)
18-
display(bs)
19-
2018
as = adjustment_sets(dag, :x2, :y)
21-
display(as)
19+
20+
@testset "Test_descendents_02" begin
21+
22+
@test length(bs) == 48
23+
@test bs[44] == [:y, :k1, :w, :k2]
24+
@test bs[45] == [:y, :k1, :w, :x2, :k2]
25+
@test bs[46] == [:y, :k1, :w, :x3, :k2]
26+
@test bs[47] == [:y, :k1, :x2, :x3, :k2]
27+
@test bs[48] == [:y, :k1, :w, :x2, :x3, :k2]
28+
29+
end
30+
31+
@testset "Adjustment_sets" begin
32+
33+
@test length(as) == 5
34+
@test as[1] == [:v]
35+
@test as[2] == [:x1]
36+
@test as[3] == [:k1]
37+
@test as[4] == [:k2]
38+
@test as[5] == [:w, :x3]
39+
40+
end

test/test_descendents_03.jl

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,33 @@ d_str = "dag{k1 -> k2;k2 -> y;v -> x2;w -> k1;x1 -> v;x1 -> w;x2 -> y;x3 -> w;x3
44

55
dag = DAG("test_desc", d_str)
66

7-
to_dagitty(dag) |> display
7+
to_dagitty(dag)
88

99
fname = joinpath(ProjDir, "test_descendents_03.dot")
1010
to_graphviz(dag, fname)
11-
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
11+
#Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
1212

1313
bs = basis_set(dag)
14-
bs |> display
15-
1614
as = adjustment_sets(dag, :x2, :y)
17-
display(as)
1815

16+
@testset "Test_descendents_03" begin
17+
18+
@test length(bs) == 48
19+
@test bs[44] == [:y, :k1, :w, :k2]
20+
@test bs[45] == [:y, :k1, :w, :x2, :k2]
21+
@test bs[46] == [:y, :k1, :w, :x3, :k2]
22+
@test bs[47] == [:y, :k1, :x2, :x3, :k2]
23+
@test bs[48] == [:y, :k1, :w, :x2, :x3, :k2]
24+
25+
end
26+
27+
@testset "Adjustment_sets" begin
28+
29+
@test length(as) == 5
30+
@test as[1] == [:v]
31+
@test as[2] == [:x1]
32+
@test as[3] == [:k1]
33+
@test as[4] == [:k2]
34+
@test as[5] == [:w, :x3]
35+
36+
end

test/test_graphviz_conversions.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ d = from_ggm("DAG(
2626
);
2727

2828
dag = DAG("marks", d, df=df);
29+
2930
fn = joinpath(mktempdir(), "marks.dot")
3031
to_graphviz(dag, fn)
3132
#Sys.isapple() && run(`open -a GraphViz.app $(fn)`)
@@ -34,4 +35,4 @@ to_graphviz(dag, fn)
3435

3536
@test read(fn, String) == "digraph marks {\n algebra -> vectors;\n algebra -> mechanics;\n algebra -> analysis;\n algebra -> statistics;\n vectors -> mechanics;\n analysis -> statistics;\n}\n"
3637

37-
end
38+
end

0 commit comments

Comments
 (0)