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

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
() | () () |
_ _ | | __ _ | Type “?” for help, “]?” for Pkg help.
| | | | | | |/ ` | |
| | |
| | | | (
| | | Version 1.0.3 (2018-12-18)
/ |_|||_’_| | Official 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>

The KS-statistic value is `sqrt(tmp.n_x*tmp.n_y/(tmp.n_x + tmp.n_y)) * tmp.δ` (see e.g. here).

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

``````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.

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> 1+1
2

julia>
```
``````
1 Like