# Kolmogorov–Smirnov test, retrieve output

**URL:** <https://discourse.julialang.org/t/kolmogorov-smirnov-test-retrieve-output/1480>\
**Category:** Statistics\
**Tags:** question\
**Created:** [January 14, 2017, 12:22pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-retrieve-output/1480 "2017-01-14T12:22:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![evolgenomology](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@evolgenomology](https://discourse.julialang.org/u/evolgenomology)\
**Post date:** [January 14, 2017, 12:22pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-retrieve-output/1480/1 "2017-01-14T12:22:20Z")

</div>

Hi,

I would like to use the KS test on 2000 datasets and each time I run it just retrieve the output values into an array. Being quite new to Julia, I wonder how (and if) this is possible. Currently, I am doing ApproximateTwoSampleKSTest(x11,y11) which prints out all results to the screen like this

> ## Approximate two sample Kolmogorov-Smirnov test
> 
> Population details:  
> parameter of interest: Supremum of CDF differences  
> value under h\_0: 0.0  
> point estimate: 0.1540000000000001

> Test summary:  
> outcome with 95% confidence: reject h\_0  
> two-sided p-value: 1.0030026093285193e-10 (extremely significant)

> Details:  
> number of observations: [1000,1000]  
> KS-statistic: 3.443544685349679

Thanks

Philipp

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [January 14, 2017, 12:48pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-retrieve-output/1480/2 "2017-01-14T12:48:25Z")

</div>

You can save the whole objects into an array easily, e.g. by `results[11] = ApproximateTwoSampleKSTest(x11, y11)`, or if you are only after the p value you can `results[11] = pvalue(ApproximateTwoSampleKSTest(x11, y11))`. Interestingly, there does not seem to be a function to get the test statistic. You can get it by

```julia
function teststatistic(x)
    n = x.n_x*x.n_y/(x.n_x+x.n_y)
    sqrt(n)*x.δ
end

x = ApproximateTwoSampleKSTest(x11, y11)
teststatistic(x)

```

I have taken this code from the package source. The `x.n_x` variables above refer to the field names of the object, you can see them by e.g. `fieldnames(x)`.

---

<div class="post-metadata">

**Author:** ![evolgenomology](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@evolgenomology](https://discourse.julialang.org/u/evolgenomology)\
**Post date:** [January 14, 2017, 1:42pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-retrieve-output/1480/3 "2017-01-14T13:42:33Z")

</div>

Thanks!

Ja, I used the  
`results[11] = ApproximateTwoSampleKSTest(x11, y11)`  
option, and even figured out the pvalue function in the meantime, but I was really interested in storing the test statistics for all my 2000 tests. So great, thanks a lot.

P
