# How do I find a p value with HypothesisTests.jl?

**URL:** <https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758>\
**Category:** Statistics\
**Tags:** question, package, statistics, type\
**Created:** [May 8, 2021, 5:37am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758 "2021-05-08T05:37:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 8, 2021, 5:37am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/1 "2021-05-08T05:37:06Z")

</div>

The documentation provides the example:

```julia
pvalue(test::HypothesisTest; tail = :both)

```

but how do I enter this ie.

```julia
using HypothesisTests
pvalue(pvalue(ApproximateTwoSampleKSTest(x,y); :both)

```

isn’t accepted, so how do i put in that I want a two tailed sample? Unless I want the left or right tail.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 8, 2021, 7:12am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/2 "2021-05-08T07:12:06Z")

</div>

The documented function signature is telling you that `:both` is the default value for the `tail` keyword argument, so if you don’t supply an alternative value, you will be getting the two-tailed p-value:

```julia
julia> using HypothesisTests

julia> x = randn(100_000); y = randn(100_000);

julia> pvalue(ApproximateTwoSampleKSTest(x, y))
0.4162728684426016

julia> pvalue(ApproximateTwoSampleKSTest(x, y); tail = :both)
0.4162728684426016

julia> pvalue(ApproximateTwoSampleKSTest(x, y); tail = :left)
0.49284527402027806

julia> pvalue(ApproximateTwoSampleKSTest(x, y); tail = :right)
0.21008354374916968

```

As an aside, I think I’ve mentioned it before but to reiterate it would be really good if you could copy/paste your own MWE into a fresh Julia session and run it before you post, to ensure that it actually reproduces the error you’re seeing. What you posted above doesn’t run as you’re missing a parenthesis at the end. Also note that when supplying keyword arguments you need to name them, i.e. `tail = :both` rather than just `:both`

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 8, 2021, 7:46am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/3 "2021-05-08T07:46:43Z")

</div>

> [@nilshg](#):
>
> `pvalue(ApproximateTwoSampleKSTest(x, y))`

```julia
begin
	Pkg.add("HypothesisTests")
	using HypothesisTests
end

```

```julia
pvalue(ApproximateTwoSampleKSTest(x, y))

```

MethodError: no method matching pvalue(::HypothesisTests.ApproximateTwoSampleKSTest)

Closest candidates are:

pvalue(!Matched::HypothesisTests.ApproximateOneSampleKSTest; tail) at /home/brett/Documents/BEST.jl#==#0979e6f0-e5f0-4c29-8b3b-cc2ef56a2241:1

1. **top-level scope** @ _[Local: 1](http://localhost:1234/edit?id=3c741c54-af8b-11eb-2850-c1014c12b008#)_ [inlined]

```julia
pvalue(ApproximateTwoSampleKSTest(x, y); tail = :both

```

MethodError: no method matching pvalue(::HypothesisTests.ApproximateTwoSampleKSTest; tail=:both)

Closest candidates are:

pvalue(!Matched::HypothesisTests.ApproximateOneSampleKSTest; tail) at /home/brett/Documents/BEST.jl#==#0979e6f0-e5f0-4c29-8b3b-cc2ef56a2241:1

1. **top-level scope** @ _[Local: 1](http://localhost:1234/edit?id=3c741c54-af8b-11eb-2850-c1014c12b008#)_ [inlined]

```julia
pvalue(ApproximateTwoSampleKSTest(x, y); tail = :left)

```

MethodError: no method matching pvalue(::HypothesisTests.ApproximateTwoSampleKSTest; tail=:both)

Closest candidates are:

pvalue(!Matched::HypothesisTests.ApproximateOneSampleKSTest; tail) at /home/brett/Documents/BEST.jl#==#0979e6f0-e5f0-4c29-8b3b-cc2ef56a2241:1

1. **top-level scope** @ _[Local: 1](http://localhost:1234/edit?id=3c741c54-af8b-11eb-2850-c1014c12b008#)_ [inlined]

```julia
pvalue(ApproximateTwoSampleKSTest(x, y); tail = :left)

```

MethodError: no method matching pvalue(::HypothesisTests.ApproximateTwoSampleKSTest; tail=:right)

Closest candidates are:

pvalue(!Matched::HypothesisTests.ApproximateOneSampleKSTest; tail) at /home/brett/Documents/BEST.jl#==#0979e6f0-e5f0-4c29-8b3b-cc2ef56a2241:1

top-level scope@Local: 1[inlined]

Does it matter that I’m using Pluto? how do i ensure I’m adding the latest version of packages in Pluto?

---

<div class="post-metadata">

**Author:** ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)\
**Post date:** [May 8, 2021, 7:56am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/4 "2021-05-08T07:56:26Z")

</div>

It

```
has

```

been said before, this is

- difficult

to read.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 8, 2021, 7:57am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/5 "2021-05-08T07:57:48Z")

</div>

I figured out that there was a conflict with other packages. There is also a problem that Pluto cuts stuff off.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [May 8, 2021, 8:26am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/6 "2021-05-08T08:26:03Z")

</div>

> [@brett\_knoss](#):
>
> ```julia
> using HypothesisTests
> pvalue(pvalue(ApproximateTwoSampleKSTest(x,y); :both)
> 
> ```

Additionally, in your initial example, the code attempts to compute a p-value of a p-value, which of course, would be invalid.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 8, 2021, 8:56am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/7 "2021-05-08T08:56:51Z")

</div>

Can I again suggest that for any problem you have, you try running the code in a fresh REPL session (NOT Pluto) to isolate where the issue comes from - from many of your posts I get the impression that the majority of your issues comes from incorrect usage of Pluto, rather than from the packages you’re using.

IJulia might also be a good alternative as it’s behaviour is pretty much like the plain REPL.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [May 8, 2021, 10:55am UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/8 "2021-05-08T10:55:35Z")

</div>

Yes, **please** do your homework before posting here @brett_knoss. We have all kinds of members in the forum with all levels of expertise willing to help. However, if you start to just dump any error you get here, people will treat it as SPAM.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [May 8, 2021, 4:26pm UTC](https://discourse.julialang.org/t/how-do-i-find-a-p-value-with-hypothesistests-jl/60758/9 "2021-05-08T16:26:31Z")

</div>

Ok, I’ll try to test things more carefully. I’m having trouble using the HypothesisTests.jl tutorial, because it doesn’t provide examples with working variables. Other tutorials would benefit from this as well. I think this is one of the goals of Pluto, with sample notebooks.
