|
| 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 | +to_dagitty(dag) |> display |
| 10 | + |
| 11 | +#= |
| 12 | +fname = joinpath(ProjDir, "test_descendents_03.dot") |
| 13 | +to_graphviz(dag, fname) |
| 14 | +Sys.isapple() && run(`open -a GraphViz.app $(fname)`) |
| 15 | +=# |
| 16 | + |
| 17 | +display(dag) |
| 18 | + |
| 19 | +bs = basis_set(dag) |
| 20 | +bs |> display |
| 21 | + |
| 22 | +show(ConditionalIndependency(bs[1])) |
| 23 | +@show d_separation(dag, :k1, :y, cset=[:w, :k2, :x2, :x3]) |
| 24 | +@show d_separation(dag, :k1, :y, cset=[:k2, :x1, :x3]) |
| 25 | +@show d_separation(dag, :k1, :y, cset=[:k2, :x2, :x3]) |
| 26 | +@show d_separation(dag, :k1, :y, cset=[:k2, :x2, :x3]) |
| 27 | +@show d_separation(dag, :k1, :y, cset=[:k2, :v, :x3]) |
| 28 | +@show d_separation(dag, :k1, :y, cset=[:k2, :x1, :x3]) |
| 29 | +@show d_separation(dag, :k1, :y, cset=[:k2, :x1]) |
| 30 | +@show d_separation(dag, :k1, :y, cset=[:k2, :x3]) |
| 31 | +@show d_separation(dag, :k1, :y, cset=[:k2, :w]) |
| 32 | +@show d_separation(dag, :k1, :y, cset=[:w]) |
| 33 | +@show d_separation(dag, :k1, :y, cset=[:k2]) |
| 34 | +println() |
| 35 | + |
| 36 | +#= |
| 37 | +@show d_separation(dag, :k1, :v, cset=[:x1]) |
| 38 | +@show d_separation(dag, :k1, :v, cset=[:w]) |
| 39 | +@show d_separation(dag, :k1, :x1, cset=[:w]) |
| 40 | +@show d_separation(dag, :k1, :x2, cset=[:v]) |
| 41 | +@show d_separation(dag, :k1, :x2, cset=[:x1]) |
| 42 | +@show d_separation(dag, :k1, :x2, cset=[:w]) |
| 43 | +@show d_separation(dag, :k1, :x3, cset=[:w]) |
| 44 | +
|
| 45 | +bs[9] |> display |
| 46 | +@show d_separation(dag, :x1, :x2; cset=[:v]) |
| 47 | +println() |
| 48 | +
|
| 49 | +bs[10] |> display |
| 50 | +@show d_separation(dag, :x1, :x3) |
| 51 | +println() |
| 52 | +
|
| 53 | +bs[11] |> display |
| 54 | +@show d_separation(dag, :x1, :k1; cset=[:w]) |
| 55 | +println() |
| 56 | +
|
| 57 | +bs[12] |> display |
| 58 | +@show d_separation(dag, :x1, :k2; cset=[:k2]) |
| 59 | +println() |
| 60 | +
|
| 61 | +bs[13] |> display |
| 62 | +@show d_separation(dag, :x1, :y; cset=[:x2, :x3, :k2]) |
| 63 | +println() |
| 64 | +
|
| 65 | +@show d_separation(dag, :k2, :v, cset=[:x1]) |
| 66 | +@show d_separation(dag, :k2, :v, cset=[:w]) |
| 67 | +@show d_separation(dag, :k2, :v, cset=[:k1]) |
| 68 | +@show d_separation(dag, :k2, :w, cset=[:k1]) |
| 69 | +@show d_separation(dag, :k2, :x1, cset=[:w]) |
| 70 | +@show d_separation(dag, :k2, :x1, cset=[:k1]) |
| 71 | +@show d_separation(dag, :k2, :x2, cset=[:v]) |
| 72 | +@show d_separation(dag, :k2, :x2, cset=[:x1]) |
| 73 | +@show d_separation(dag, :k2, :x2, cset=[:w]) |
| 74 | +@show d_separation(dag, :k2, :x2, cset=[:k1]) |
| 75 | +@show d_separation(dag, :k2, :x3, cset=[:w]) |
| 76 | +@show d_separation(dag, :k2, :x3, cset=[:k1]) |
| 77 | +println() |
| 78 | +
|
| 79 | +@show d_separation(dag, :v, :w; cset=:x1) |
| 80 | +@show d_separation(dag, :v, :x3) |
| 81 | +@show d_separation(dag, :v, :y; cset=[:k2, :x2, :x3]) |
| 82 | +@show d_separation(dag, :v, :y; cset=[:k1, :x2, :x3]) |
| 83 | +@show d_separation(dag, :v, :y; cset=[:w, :x2, :x3]) |
| 84 | +@show d_separation(dag, :v, :y; cset=[:x2, :x1]) |
| 85 | +println() |
| 86 | +
|
| 87 | +@show d_separation(dag, :w, :x2; cset=[:v]) |
| 88 | +@show d_separation(dag, :w, :x2; cset=[:x1]) |
| 89 | +@show d_separation(dag, :w, :y; cset=[:k2, :x2, :x3]) |
| 90 | +@show d_separation(dag, :w, :y; cset=[:k2, :v, :x3]) |
| 91 | +@show d_separation(dag, :w, :y; cset=[:k1, :x2, :x3]) |
| 92 | +@show d_separation(dag, :w, :y; cset=[:k1, :v, :x3]) |
| 93 | +@show d_separation(dag, :w, :y; cset=[:k1, :x1, :x3]) |
| 94 | +@show d_separation(dag, :w, :y; cset=[:k2, :x2, :x3]) |
| 95 | +println() |
| 96 | +
|
| 97 | +@show d_separation(dag, :x1, :y; cset=[:k1, :v, :x3]) |
| 98 | +@show d_separation(dag, :x1, :y; cset=[:v, :w, :x3]) |
| 99 | +println() |
| 100 | +
|
| 101 | +@show d_separation(dag, :x2, :x3) |
| 102 | +println() |
| 103 | +=# |
0 commit comments