Skip to content

Commit f2369de

Browse files
committed
Rel 0.1.0
1 parent 569b690 commit f2369de

10 files changed

Lines changed: 42 additions & 49 deletions

File tree

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ git:
1616

1717
jobs:
1818
include:
19-
- stage: TestPreviousRelease
20-
os: linux
2119
- stage: TestLatestRelease
2220
julia: 1.5
2321
os: linux

docs/src/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ DAG(name::AbstractString, d::OrderedDict, df::DataFrame)
1515

1616
## d_separation
1717
```@docs
18-
d_separation(d::DAG, first::SymbolList, second::SymbolList; debug=false)
19-
d_separation(d::DAG, first::SymbolList, second::SymbolList, cond::SymbolList; debug=false)
18+
d_separation(d::DAG, first::SymbolList, second::SymbolList; cond::SymbolListOrNothing, debug=false)
2019
```
2120

2221
## shipley_test

examples/derived/derived.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,31 @@ Wei 27.494715 33.118393 60.609937 24.834038 113.66808
2525
";
2626

2727
# A DAG model with a latent variable U
28-
# G = DAG(Y ~ Z + U, X ~ U + W, Z ~ W)
29-
dag = DAG("ggm_derived", "DAG(Y ~ Z + U, X ~ U + W, Z ~ W)")
28+
dag = DAG("ggm_derived", "DAG(y ~ z + u, x ~ u + w, z ~ w)")
3029

3130
to_dagitty(dag.d) |> display
3231

3332
fname = ProjDir * "/derived.dot"
3433
to_graphviz(dag, fname)
3534
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
3635

36+
set_dag_df!(dag, df; force=true)
37+
3738
println("Definition of DAG:")
3839
display(dag)
3940

40-
println("Adjacency matrix:")
41-
display(dag.a)
41+
bs = basis_set(dag; debug=true)
42+
display(bs)
4243

43-
println("\nAncestral graph:")
44-
ag = ancestral_graph(dag; m=[:u])
45-
display(ag)
44+
#t = shipley_test(dag)
45+
#display("shipley_test = $t"); println()
4646

47-
println()
48-
set_dag_df!(dag, df; force=true)
49-
display(dag.s)
50-
51-
println()
52-
bs = basis_set(dag)
53-
display(bs)
47+
pt = pcor_test(dag, [:w, :y], 1, 44)
48+
display("pcor_test = $pt"); println()
5449

5550
as = adjustment_sets(dag, :w, :z)
5651
as |> display
52+
53+
println("\nAncestral graph:")
54+
ag = ancestral_graph(dag; m=[:u])
55+
display(ag)

examples/marks/marks.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,19 @@ Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
4444

4545
display(dag.s); println()
4646

47-
#=
48-
ord = topological_order(dag)
49-
display(ord); println()
50-
display(dag.vars[ord]); println()
51-
=#
52-
5347
bs = basis_set(dag)
5448
display(bs); println()
5549

5650
t = shipley_test(dag)
57-
display(t); println()
51+
display("shipley_test = $t"); println()
52+
53+
pt = pcor_test(dag, [:analysis, :statistics, :mechanics], 1, 88)
54+
display("pcor_test = $pt"); println()
5855

5956
f = [:statistics]; s = [:mechanics]; sel = vcat(f, s)
60-
cond = :algebra
6157

62-
e = d_separation(dag, f, s, cond)
63-
println("d_separation($(dag.name), $f, $s, $cond) = $e")
58+
e = d_separation(dag, f, s, :algebra)
59+
println("d_separation($(dag.name), $f, $s, :algebra) = $e")
6460

6561
e = d_separation(dag, f, s)
6662
println("d_separation($(dag.name), $f, $s) = $e")

src/StructuralCausalModels.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Part of the API, exported.
2727
"""
2828
scm_path(parts...) = normpath(joinpath(scm_src_path, parts...))
2929

30-
SymbolList = Union{Symbol, Vector{Symbol}, Nothing}
31-
#SymbolListOrNothing = Union{SymbolList, Nothing}
30+
SymbolList = Union{Symbol, Vector{Symbol}}
31+
SymbolListOrNothing = Union{SymbolList, Nothing}
3232
OrderedDictOrNothing = Union{OrderedDict, Nothing}
3333
NamedArrayOrNothing = Union{NamedArray, Nothing}
3434
DataFrameOrNothing = Union{DataFrame, Nothing}

src/methods/d_separation.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ d_separation(
1616
)
1717
```
1818
19-
### Optional arguments
19+
### Keyword arguments
2020
```julia
21-
* `cond::SymbolList` : Conditioning set
21+
* `cond::SymbolListOrNoting=noting` : Conditioning set
2222
* `debug=false` : Trace execution
2323
```
2424
@@ -61,19 +61,22 @@ The Julia translation is licenced under: MIT.
6161
6262
Part of the API, exported.
6363
"""
64-
function d_separation(d::DAG, first::SymbolList, second::SymbolList; debug=false)
64+
function d_separation(d::DAG, first::SymbolList, second::SymbolList;
65+
cond::SymbolListOrNothing=nothing, debug=false)
6566

6667
e = induced_covariance_graph(d, vcat(first, second), SymbolList[]; debug=debug)
6768
sum(e[first, second]) == 0
6869

6970
end
7071

72+
#=
7173
function d_separation(d::DAG, first::SymbolList, second::SymbolList, cond::SymbolList; debug=false)
7274
7375
e = induced_covariance_graph(d, vcat(first, second), cond; debug=debug)
7476
sum(e[first, second]) == 0
7577
7678
end
79+
=#
7780

7881
export
7982
d_separation

src/methods/pcor.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ variables.
1010
### Method
1111
```julia
1212
pcor(;
13+
* `d::DAG` : DAG object
1314
* `u::Vector{Symbol}` : Variables used to compute correlation
14-
* `S::Matrix` : Sample covariance matrix
1515
)
1616
```
1717
where:
@@ -53,9 +53,9 @@ The Julia translation is licenced under: MIT.
5353
5454
Part of the api, not exported.
5555
"""
56-
function pcor(u::Vector{Symbol}, S::NamedArray)
56+
function pcor(d:: DAG, u::SymbolList)
5757
us = String.(u)
58-
k = inv(S[us, us])
58+
k = inv(d.s[us, us])
5959
-k[1,2] / sqrt(k[1,1] * k[2,2])
6060
end
6161

src/methods/pcor_test.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ The Julia translation is licenced under: MIT.
5151
5252
Part of the api, not exported.
5353
"""
54-
function pcor_test(r, q, n)
54+
function pcor_test(d::DAG, u::SymbolList, q, n)
5555

56+
r = pcor(d, u)
5657
df = n - 2 - q
5758
tval = r * sqrt(df) / sqrt(1 - r*r)
58-
pv = 2 * pdf(TDist(-abs(tval), df))
59+
pv = 2 * cdf(TDist(df), -abs(tval))
5960
(pv=tval, df=df, pvalue=pv)
6061

61-
end
62+
end
63+
64+
export
65+
pcor_test

src/methods/shipley_test.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ function shipley_test(d::DAG)
103103
p = zeros(k)
104104
for i in 1:k
105105
u = append(l[i])
106-
r = pcor(u, d.s)
106+
println(u)
107+
r = pcor(d, u)
107108
q = length(u) - 2
108109
p[i] = pval(r, q, n)
109110
end

src/types/ConditionalIndependence.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import Base: show, getindex, iterate, HasLength, HasEltype, length
22

3-
#=
4-
println("\u2561\u255E")
5-
println("\u2210")
6-
println("\u2550\u2550")
7-
println("\u21d0 \u21d1 \u21d2 \u27f9 \u21e2")
8-
=#
9-
103
struct ConditionalIndependency
114
f::SymbolList
125
s::SymbolList
13-
c::SymbolList
6+
c::SymbolListOrNothing
147
end
158

169
ConditionalIndependency(f::SymbolList, s::SymbolList) =
@@ -34,7 +27,7 @@ end
3427

3528
function append(c::ConditionalIndependency)
3629
v = [c.f, c.s]
37-
length(c.c) > 0 && push!(v, c.c...)
30+
!isnothing(c.c) && length(c.c) > 0 && push!(v, c.c...)
3831
v
3932
end
4033

0 commit comments

Comments
 (0)