Skip to content

Commit 88be8f2

Browse files
committed
Rel 0.1.0
1 parent 91c2337 commit 88be8f2

8 files changed

Lines changed: 80 additions & 37 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[![codecov.io](http://codecov.io/github/StatisticalRethinkingJulia/StructuralCausalModels.jl/coverage.svg?branch=master)](http://codecov.io/github/StatisticalRethinkingJulia/StructuralCausalModels.jl?branch=master)
1111
[![Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://StatisticalRethinkingJulia.github.io/StructuralCausalModels.jl/stable)
1212
[![Documentation](https://img.shields.io/badge/docs-master-blue.svg)](https://StatisticalRethinkingJulia.github.io/StructuralCausalModels.jl/dev)
13+
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
1314

1415
# Introduction
1516

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ DAG(name::AbstractString, d::OrderedDict, df::DataFrame)
1616
## d_separation
1717
```@docs
1818
d_separation(d::DAG, first::SymbolList, second::SymbolList; debug=false)
19-
```
19+
d_separation(d::DAG, first::SymbolList, second::SymbolList, cond::SymbolList; debug=false)```
2020
2121
## shipley_test
2222
```@docs

docs/src/walkthrough.md

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Rows ╲ Cols │ :mechanics :vectors :algebra :analysis :statistic
7777

7878
Additional DAG related functions are `adjacency_matrix()`, `edge_matrix()`, `to_ggm()`, `from_ggm()`, `to_dagitty()`, `from_dagitty()`, `set_dag_df!()` and `set_dag_cov_matrix!()`.
7979

80-
# D_separation
80+
# Directed separation
8181

8282
Given a causal graph, `d_separation(dag, f, l, cond)` determines if the vertices in set `f` are `d-separated` from the vertices in set `l` given the conditioning set `cond`.
8383

@@ -194,10 +194,9 @@ fname = scm_path("..", "examples", "SR", "SR6.4.3", "sr6.4.3.dot")
194194
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
195195

196196
d = OrderedDict(
197-
:s => [:a, :m, :w],
198-
:a => [:m, :d],
199-
:m => [:d],
200-
:w => [:d]
197+
[:a, :m, :w] => :s,
198+
:d => [:w, :m, :a],
199+
:m => [:a]
201200
);
202201
u = []
203202

@@ -225,7 +224,7 @@ println()
225224
```
226225

227226
for this [DAG](https://github.com/StatisticalRethinkingJulia/StructuralCausalModels.jl/blob/master/examples/SR/SR6.4.3/sr6.4.3.pdf) returns:
228-
```
227+
```julia
229228
4-element Array{Array{Symbol,1},1}:
230229
[:w, :s, :a, :d]
231230
[:w, :s, :a, :m, :d]
@@ -245,35 +244,15 @@ println()
245244
[:w, :s, :m, :d]
246245
[:w, :s, :m, :a, :d]
247246

248-
openpaths = open_paths(dag, backdoorpaths)
249-
println("All open (backdoor) paths between :w and :d:")
250-
openpaths |> display
251-
println()
252-
253-
3-element Array{Array{Symbol,1},1}:
254-
[:w, :s, :a, :d]
255-
[:w, :s, :a, :m, :d]
256-
[:w, :s, :m, :d]
257247
```
258-
259-
Not exported `blocking_sets()`:
260-
```jula
261-
StructuralCausalModels.blocking_sets(openpaths)
262-
4-element Array{Array{Symbol,1},1}:
263-
[:w]
264-
[:s]
265-
[:d]
266-
[:a, :m]
267-
248+
```julia
268249
println("Show path: $(allpaths[2])")
269250
show_dag_path(dag, allpaths[2]) |> display
270251
println()
271252

272253
":w ⇐ :s ⇒ :a ⇒ :m ⇒ :d"
273254
```
274255

275-
The vertices :w and :d will be removed by `adjustment_sets()`.
276-
277256
# Ancestral graph
278257

279258
Setup an ancestral_graph example:

examples/SR/SR6.4.3/sr6.4.3.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ if isdefined(Main, :StatsPlots)
2121
end
2222

2323
d = OrderedDict(
24-
:w => :s,
24+
[:w, :m, :a] => :s,
2525
:d => [:a, :w, :m],
26-
:m => [:a, :s],
27-
:a => :s
26+
:m => [:a]
2827
);
2928

3029
dag = DAG("sr6_4_3", d, df);

src/StructuralCausalModels.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ include("methods/basis_set.jl")
4242
include("methods/shipley_test.jl")
4343
include("methods/d_separation.jl")
4444
include("methods/pcor.jl")
45+
include("methods/pcor_test.jl")
4546
include("methods/induced_covariance_graph.jl")
4647
include("methods/all_paths.jl")
4748
include("methods/open_paths.jl")

src/methods/d_separation.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ d_separation(
1818
1919
### Optional arguments
2020
```julia
21-
* `cond::Vector{Symbol}` : Conditioning set
21+
* `cond::SymbolList` : Conditioning set
2222
* `debug=false` : Trace execution
2323
```
2424
@@ -61,17 +61,16 @@ 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,
65-
cond::SymbolList; debug=false)
64+
function d_separation(d::DAG, first::SymbolList, second::SymbolList; debug=false)
6665

67-
e = induced_covariance_graph(d, vcat(first, second), cond; debug=debug)
66+
e = induced_covariance_graph(d, vcat(first, second), SymbolList[]; debug=debug)
6867
sum(e[first, second]) == 0
6968

7069
end
7170

72-
function d_separation(d::DAG, first::SymbolList, second::SymbolList; debug=false)
71+
function d_separation(d::DAG, first::SymbolList, second::SymbolList, cond::SymbolList; debug=false)
7372

74-
e = induced_covariance_graph(d, vcat(first, second), SymbolList[]; debug=debug)
73+
e = induced_covariance_graph(d, vcat(first, second), cond; debug=debug)
7574
sum(e[first, second]) == 0
7675

7776
end

src/methods/pcor.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ function pcor(u::Vector{Symbol}, S::NamedArray)
5858
k = inv(S[us, us])
5959
-k[1,2] / sqrt(k[1,1] * k[2,2])
6060
end
61+
62+
export
63+
pcor

src/methods/pcor_test.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#=
2+
"pcor.test" <-
3+
function(r, q, n){
4+
df = n - 2 - q
5+
tval <- r * sqrt(df)/sqrt(1-r*r)
6+
pv <- 2 * pt(-abs(tval), df)
7+
list(tval = tval, df = df, pvalue = pv)
8+
9+
}
10+
=#
11+
12+
"""
13+
14+
# pcor
15+
16+
$(SIGNATURES)
17+
18+
Computes the partial correlation between two variables given a set of other
19+
variables.
20+
21+
### Method
22+
```julia
23+
pcor_test(;
24+
* `u::Vector{Symbol}` : Variables used to compute correlation
25+
* `S::Matrix` : Sample covariance matrix
26+
)
27+
```
28+
where:
29+
30+
u[1], u[2]: Variables used to compute correlation between, remaining variables
31+
are the conditioning set
32+
33+
34+
### Returns
35+
```julia
36+
* `res::Float64` : Correlation between u[1] and u[2]
37+
```
38+
# Extended help
39+
40+
### Acknowledgements
41+
42+
Original author: Giovanni M. Marchetti
43+
44+
Translated to Julia: Rob J Goedman
45+
46+
### License
47+
48+
The R package ggm is licensed under License: GPL-2.
49+
50+
The Julia translation is licenced under: MIT.
51+
52+
Part of the api, not exported.
53+
"""
54+
function pcor_test(r, q, n)
55+
56+
df = n - 2 - q
57+
tval = r * sqrt(df) / sqrt(1 - r*r)
58+
pv = 2 * pdf(TDist(-abs(tval), df))
59+
(pv=tval, df=df, pvalue=pv)
60+
61+
end

0 commit comments

Comments
 (0)