# How to Capture Full Output of a HypothesisTest.jl Test?

**URL:** <https://discourse.julialang.org/t/how-to-capture-full-output-of-a-hypothesistest-jl-test/20336>\
**Category:** New to Julia\
**Created:** [January 31, 2019, 11:29pm UTC](https://discourse.julialang.org/t/how-to-capture-full-output-of-a-hypothesistest-jl-test/20336 "2019-01-31T23:29:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jort](https://avatars.discourse-cdn.com/v4/letter/j/c37758/32.png) [@jort](https://discourse.julialang.org/u/jort)\
**Post date:** [January 31, 2019, 11:29pm UTC](https://discourse.julialang.org/t/how-to-capture-full-output-of-a-hypothesistest-jl-test/20336/1 "2019-01-31T23:29:43Z")

</div>

Newbie question that probably relates to other structures, but I encountered it trying to use ApproximateTwoSampleKSTest. When I run it, I get a summary “report” back to the screen. Using dump(), I can see the 5 elements of the struct that is returned. I can use pvalue() to get the p-value.

But how can I capture, say, the “KS-statistic” value, or the text of the test summary outcome into a variable?

```
           _

```

\_ \_ _(_)\_ | Documentation: [https://docs.julialang.org](https://docs.julialang.org)  
(_) | (_) (_) |  
\_ \_ | | \_\_ \_ | Type “?” for help, “]?” for Pkg help.  
| | | | | | |/ ` | |  
| | || | | | (_| | | Version 1.0.3 (2018-12-18)  
_/ |\ __‘_|_|_|\__ ’\_| | Official [https://julialang.org/](https://julialang.org/) release  
|\_\_/ |

julia\> using HypothesisTests

## julia\> tmp = ApproximateTwoSampleKSTest([1,3,5,7],[2,4,6,8]) Approximate two sample Kolmogorov-Smirnov test

Population details:  
parameter of interest: Supremum of CDF differences  
value under h\_0: 0.0  
point estimate: 0.25

Test summary:  
outcome with 95% confidence: fail to reject h\_0  
two-sided p-value: 0.9996

Details:  
number of observations: [4,4]  
KS-statistic: 0.3535533905932738

julia\> dump(tmp)  
ApproximateTwoSampleKSTest  
n\_x: Int64 4  
n\_y: Int64 4  
δ: Float64 0.25  
δp: Float64 0.25  
δn: Float64 -0.0

julia\> pvalue(tmp)  
0.9996332921577278

julia\> tmp.n\_x  
4

julia\>

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [February 1, 2019, 8:05am UTC](https://discourse.julialang.org/t/how-to-capture-full-output-of-a-hypothesistest-jl-test/20336/2 "2019-02-01T08:05:08Z")

</div>

The KS-statistic value is `sqrt(tmp.n_x*tmp.n_y/(tmp.n_x + tmp.n_y)) * tmp.δ` (see e.g. [here](https://github.com/JuliaStats/HypothesisTests.jl/blob/be0aefc456fcf5fea1bfab765c3b6dac81423018/src/kolmogorov_smirnov.jl#L178)).

To capture the output into a string variable, you could do

```julia
io = IOBuffer();
show(io, "text/plain", tmp)
textsummary = String(take!(io))

```

But I don’t know how useful this is, if you want to further process the data.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [February 1, 2019, 1:17pm UTC](https://discourse.julialang.org/t/how-to-capture-full-output-of-a-hypothesistest-jl-test/20336/3 "2019-02-01T13:17:19Z")

</div>

Fyi, you can wrap code in triple backticks (the symbol next to the numeral 1, at least on American keyboards) to get money formatting of code. Like so:

````julia
```
julia> 1+1
  2

julia>
```

````
