Repository: JuliaStats/HypothesisTests.jl
Pull request #264 (2022-03-04 00:46:51)

Fix some type instabilities of `pvalue` + `confint`
This PR fixes a part of https://github.com/JuliaStats/HypothesisTests.jl/issues/263.

codecov-commenter: # [Codecov](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats) Report
> Merging [#264](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats) (c21c0ed) into [master](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/commit/18e35fee26b0f048f917e39dd2f13ee644fe2420?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats) (18e35fe) will **increase** coverage by `0.45%`.
> The diff coverage is `73.33%`.

[![Impacted file tree graph](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264/graphs/tree.svg?width=650&height=150&src=pr&token=ztSoTXYVhb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats)](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats)

```diff
@@            Coverage Diff             @@
##           master     #264      +/-   ##
==========================================
+ Coverage   93.17%   93.62%   +0.45%     
==========================================
  Files          28       28              
  Lines        1714     1711       -3     
==========================================
+ Hits         1597     1602       +5     
+ Misses        117      109       -8     
```


| [Impacted Files](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats) | Coverage Δ | |
|---|---|---|
| [src/mann\_whitney.jl](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats#diff-c3JjL21hbm5fd2hpdG5leS5qbA==) | `87.50% <50.00%> (+5.57%)` | :arrow_up: |
| [src/wilcoxon.jl](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats#diff-c3JjL3dpbGNveG9uLmps) | `95.08% <76.92%> (+1.53%)` | :arrow_up: |
| [src/HypothesisTests.jl](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats#diff-c3JjL0h5cG90aGVzaXNUZXN0cy5qbA==) | `82.60% <88.88%> (+2.01%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats). Last update [18e35fe...c21c0ed](https://codecov.io/gh/JuliaStats/HypothesisTests.jl/pull/264?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaStats).


Patch:
diff --git a/Project.toml b/Project.toml
index 3f6c32f..0a93543 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,6 +1,6 @@
 name = "HypothesisTests"
 uuid = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
-version = "0.10.6"
+version = "0.10.7"
 
 [deps]
 Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
diff --git a/src/mann_whitney.jl b/src/mann_whitney.jl
index 4de0452..da1e959 100644
--- a/src/mann_whitney.jl
+++ b/src/mann_whitney.jl
@@ -134,6 +134,8 @@ function mwuenumerate(x::ExactMannWhitneyUTest)
 end
 
 function pvalue(x::ExactMannWhitneyUTest; tail=:both)
+    check_tail(tail)
+
     if x.tie_adjustment == 0
         # Compute exact p-value using method from Rmath, which is fast but
         # cannot account for ties
@@ -145,21 +147,17 @@ function pvalue(x::ExactMannWhitneyUTest; tail=:both)
             end
         elseif tail == :left
             pwilcox(x.U, x.nx, x.ny, true)
-        elseif tail == :right
+        else # tail == :right
             pwilcox(x.U - 1, x.nx, x.ny, false)
-        else
-            throw(ArgumentError("tail=$(tail) is invalid"))
         end
     else
         # Compute exact p-value by enumerating possible ranks in the tied data
         if tail == :both
-            min(1, 2 * minimum(mwuenumerate(x)))
+            min(1.0, 2 * minimum(mwuenumerate(x)))
         elseif tail == :left
             mwuenumerate(x)[1]
-        elseif tail == :right
+        else # tail == :right
             mwuenumerate(x)[2]
-        else
-            throw(ArgumentError("tail=$(tail) is invalid"))
         end
     end
 end
@@ -223,15 +221,15 @@ function show_params(io::IO, x::ApproximateMannWhitneyUTest, ident)
 end
 
 function pvalue(x::ApproximateMannWhitneyUTest; tail=:both)
+    check_tail(tail)
+
     if x.mu == x.sigma == 0
-        1
-    else
-        if tail == :both
-            2 * ccdf(Normal(), abs(x.mu - 0.5 * sign(x.mu))/x.sigma)
-        elseif tail == :left
-            cdf(Normal(), (x.mu + 0.5)/x.sigma)
-        elseif tail == :right
-            ccdf(Normal(), (x.mu - 0.5)/x.sigma)
-        end
+        1.0
+    elseif tail == :both
+        2 * ccdf(Normal(), abs(x.mu - 0.5 * sign(x.mu))/x.sigma)
+    elseif tail == :left
+        cdf(Normal(), (x.mu + 0.5)/x.sigma)
+    else # tail == :right
+        ccdf(Normal(), (x.mu - 0.5)/x.sigma)
     end
 end
diff --git a/src/wilcoxon.jl b/src/wilcoxon.jl
index 3292753..5756165 100644
--- a/src/wilcoxon.jl
+++ b/src/wilcoxon.jl
@@ -133,20 +133,22 @@ function signedrankenumerate(x::ExactSignedRankTest)
 end
 
 function pvalue(x::ExactSignedRankTest; tail=:both)
+    check_tail(tail)
+
     n = length(x.ranks)
     if n == 0
-        1
+        1.0
     elseif x.tie_adjustment == 0
         # Compute exact p-value using method from Rmath, which is fast but cannot account for ties
         if tail == :both
             if x.W <= n * (n + 1)/4
-                p = 2 * psignrank(x.W, n, true)
+                2 * psignrank(x.W, n, true)
             else
-                p = 2 * psignrank(x.W - 1, n, false)
+                2 * psignrank(x.W - 1, n, false)
             end
         elseif tail == :left
             psignrank(x.W, n, true)
-        elseif tail == :right
+        else
             psignrank(x.W - 1, n, false)
         end
     else
@@ -155,7 +157,7 @@ function pvalue(x::ExactSignedRankTest; tail=:both)
             min(1, 2 * minimum(signedrankenumerate(x)))
         elseif tail == :left
             first(signedrankenumerate(x))
-        elseif tail == :right
+        else
             last(signedrankenumerate(x))
         end
     end
@@ -223,16 +225,16 @@ function show_params(io::IO, x::ApproximateSignedRankTest, ident)
 end
 
 function pvalue(x::ApproximateSignedRankTest; tail=:both)
+    check_tail(tail)
+
     if x.mu == x.sigma == 0
-        1
-    else
-        if tail == :both
-            2 * ccdf(Normal(), abs(x.mu - 0.5 * sign(x.mu))/x.sigma)
-        elseif tail == :left
-            cdf(Normal(), (x.mu + 0.5)/x.sigma)
-        elseif tail == :right
-            ccdf(Normal(), (x.mu - 0.5)/x.sigma)
-        end
+        1.0
+    elseif tail == :both
+        2 * ccdf(Normal(), abs(x.mu - 0.5 * sign(x.mu))/x.sigma)
+    elseif tail == :left
+        cdf(Normal(), (x.mu + 0.5)/x.sigma)
+    else # tail == :right
+        ccdf(Normal(), (x.mu - 0.5)/x.sigma)
     end
 end
 
@@ -241,6 +243,7 @@ StatsBase.confint(x::ApproximateSignedRankTest; level::Real=0.95, tail=:both) =
 # implementation method inspired by these notes: http://www.stat.umn.edu/geyer/old03/5102/notes/rank.pdf
 function calculate_ci(x::AbstractVector, level::Real=0.95; tail=:both)
     check_level(level)
+    check_tail(tail)
 
     if tail == :both
         c = level
@@ -269,7 +272,7 @@ function calculate_ci(x::AbstractVector, level::Real=0.95; tail=:both)
         return (left, right)
     elseif tail == :left
         return (left, Inf)
-    elseif tail == :right
+    else # tail == :right
         return (-Inf, right)
     end
 end


Test patch:
diff --git a/src/HypothesisTests.jl b/src/HypothesisTests.jl
index 6f5c5e8..97fc110 100644
--- a/src/HypothesisTests.jl
+++ b/src/HypothesisTests.jl
@@ -69,27 +69,31 @@ If `tail` is `:both` (default), then the p-value for the two-sided test is retur
 function pvalue end
 
 # Basic function for finding a p-value given a distribution and tail
-pvalue(dist::ContinuousUnivariateDistribution, x::Number; tail=:both) =
+function pvalue(dist::ContinuousUnivariateDistribution, x::Number; tail=:both)
+    check_tail(tail)
+
     if tail == :both
-        min(2 * min(cdf(dist, x), ccdf(dist, x)), 1.0)
+        p = 2 * min(cdf(dist, x), ccdf(dist, x))
+        min(p, oneunit(p)) # if P(X = x) > 0, then possibly p > 1
     elseif tail == :left
         cdf(dist, x)
-    elseif tail == :right
+    else # tail == :right
         ccdf(dist, x)
-    else
-        throw(ArgumentError("tail=$(tail) is invalid"))
     end
+end
+
+function pvalue(dist::DiscreteUnivariateDistribution, x::Number; tail=:both)
+    check_tail(tail)
 
-pvalue(dist::DiscreteUnivariateDistribution, x::Number; tail=:both) =
     if tail == :both
-        min(2 * min(ccdf(dist, x-1), cdf(dist, x)), 1.0)
+        p = 2 * min(ccdf(dist, x-1), cdf(dist, x))
+        min(p, oneunit(p)) # if P(X = x) > 0, then possibly p > 1
     elseif tail == :left
         cdf(dist, x)
-    elseif tail == :right
+    else # tail == :right
         ccdf(dist, x-1)
-    else
-        throw(ArgumentError("tail=$(tail) is invalid"))
     end
+end
 
 function check_level(level::Float64)
     if level >= 1 || level <= 0.5
@@ -97,6 +101,12 @@ function check_level(level::Float64)
     end
 end
 
+function check_tail(tail::Symbol)
+    if tail !== :both && tail !== :left && tail !== :right
+        throw(ArgumentError("tail=$(tail) is invalid"))
+    end
+end
+
 # Pretty-print
 function Base.show(_io::IO, test::T) where T<:HypothesisTest
     io = IOContext(_io, :compact=>get(_io, :compact, true))
diff --git a/test/mann_whitney.jl b/test/mann_whitney.jl
index 68e4ec0..5076b35 100644
--- a/test/mann_whitney.jl
+++ b/test/mann_whitney.jl
@@ -3,54 +3,54 @@ using HypothesisTests: default_tail
 
 @testset "Mann-Whitney" begin
 @testset "Basic exact test" begin
-	@test abs(pvalue(ExactMannWhitneyUTest([1:10;], [2.1:2:21;])) - 0.0232) <= 1e-4
-	@test abs(pvalue(ExactMannWhitneyUTest([2.1:2:21;], [1:10;])) - 0.0232) <= 1e-4
-	@test abs(pvalue(ExactMannWhitneyUTest([1.5:10:100;], [2.1:2:21;])) - 0.0068) <= 1e-4
-	@test abs(pvalue(ExactMannWhitneyUTest([2.1:2:21;], [1.5:10:100;])) - 0.0068) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([1:10;], [2.1:2:21;]))) - 0.0232) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([2.1:2:21;], [1:10;]))) - 0.0232) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([1.5:10:100;], [2.1:2:21;]))) - 0.0068) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([2.1:2:21;], [1.5:10:100;]))) - 0.0068) <= 1e-4
 	@test default_tail(ExactMannWhitneyUTest([1:10;], [2.1:2:21;])) == :both
 	show(IOBuffer(), ExactMannWhitneyUTest([1:10;], [2.1:2:21;]))
 end
 
 @testset "Exact with ties" begin
-	@test abs(pvalue(ExactMannWhitneyUTest([1:10;], [1:10;])) - 1) <= 1e-4
-	@test abs(pvalue(ExactMannWhitneyUTest([1:10;], [2:11;])) - 0.5096) <= 1e-4
-	@test abs(pvalue(ExactMannWhitneyUTest([2:11;], [1:10;])) - 0.5096) <= 1e-4
-	@test abs(pvalue(ExactMannWhitneyUTest([1:10;], [1:5; ones(5)])) - 0.0057) <= 1e-4
-	@test abs(pvalue(ExactMannWhitneyUTest([1:5; ones(5)], [1:10;])) - 0.0057) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([1:10;], [1:10;]))) - 1) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([1:10;], [2:11;]))) - 0.5096) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([2:11;], [1:10;]))) - 0.5096) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([1:10;], [1:5; ones(5)]))) - 0.0057) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([1:5; ones(5)], [1:10;]))) - 0.0057) <= 1e-4
 	show(IOBuffer(), ExactMannWhitneyUTest([1:10;], [1:10;]))
 end
 
 @testset "Exact with ties and unequal lengths" begin
-	@test abs(pvalue(ExactMannWhitneyUTest([1:10;], [2:2:24;])) - 0.0118) <= 1e-4
-	@test abs(pvalue(ExactMannWhitneyUTest([2:2:24;], [1:10;])) - 0.0118) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([1:10;], [2:2:24;]))) - 0.0118) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest([2:2:24;], [1:10;]))) - 0.0118) <= 1e-4
 	show(IOBuffer(), ExactMannWhitneyUTest([1:10;], [2:2:24;]))
 end
 
 @testset "Approximate test" begin
-	@test abs(pvalue(ApproximateMannWhitneyUTest([1:10;], [2.1:2:21;])) - 0.0257) <= 1e-4
-	@test abs(pvalue(ApproximateMannWhitneyUTest([2.1:2:21;], [1:10;])) - 0.0257) <= 1e-4
-	@test abs(pvalue(ApproximateMannWhitneyUTest([1.5:10:100;], [2.1:2:21;])) - 0.0091) <= 1e-4
-	@test abs(pvalue(ApproximateMannWhitneyUTest([2.1:2:21;], [1.5:10:100;])) - 0.0091) <= 1e-4
-	@test default_tail(ApproximateMannWhitneyUTest([1:10;], [2.1:2:21;])) == :both
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([1:10;], [2.1:2:21;]))) - 0.0257) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([2.1:2:21;], [1:10;]))) - 0.0257) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([1.5:10:100;], [2.1:2:21;]))) - 0.0091) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([2.1:2:21;], [1.5:10:100;]))) - 0.0091) <= 1e-4
+    @test default_tail(ApproximateMannWhitneyUTest([1:10;], [2.1:2:21;])) == :both
 	show(IOBuffer(), ApproximateMannWhitneyUTest([1:10;], [2.1:2:21;]))
 end
 
 @testset "Approximate with ties" begin
-	@test abs(pvalue(ApproximateMannWhitneyUTest([1:10;], [1:10;])) - 1) <= 1e-4
-	@test abs(pvalue(ApproximateMannWhitneyUTest([1:10;], [2:11;])) - 0.4948) <= 1e-4
-	@test abs(pvalue(ApproximateMannWhitneyUTest([2:11;], [1:10;])) - 0.4948) <= 1e-4
-	@test abs(pvalue(ApproximateMannWhitneyUTest([1:10;], [1:5; ones(5)])) - 0.0076) <= 1e-4
-	@test abs(pvalue(ApproximateMannWhitneyUTest([1:5; ones(5)], [1:10;])) - 0.0076) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([1:10;], [1:10;]))) - 1) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([1:10;], [2:11;]))) - 0.4948) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([2:11;], [1:10;]))) - 0.4948) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([1:10;], [1:5; ones(5)]))) - 0.0076) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateMannWhitneyUTest([1:5; ones(5)], [1:10;]))) - 0.0076) <= 1e-4
 	show(IOBuffer(), ApproximateMannWhitneyUTest([1:10;], [1:10;]))
 end
 
 @testset "Tests for automatic selection" begin
-	@test abs(pvalue(MannWhitneyUTest([1:10;], [2.1:2:21;])) - 0.0232) <= 1e-4
-	@test abs(pvalue(MannWhitneyUTest([1:10;], [2:11;])) - 0.4948) <= 1e-4
+    @test abs(@inferred(pvalue(MannWhitneyUTest([1:10;], [2.1:2:21;]))) - 0.0232) <= 1e-4
+    @test abs(@inferred(pvalue(MannWhitneyUTest([1:10;], [2:11;]))) - 0.4948) <= 1e-4
 	show(IOBuffer(), MannWhitneyUTest([1:10;], [2.1:2:21;]))
 end
 
 @testset "Issue #39" begin
-	@test abs(pvalue(ExactMannWhitneyUTest(Float32[1:10;], Float32[2:11;])) - 0.5096) <= 1e-4
+    @test abs(@inferred(pvalue(ExactMannWhitneyUTest(Float32[1:10;], Float32[2:11;]))) - 0.5096) <= 1e-4
 end
 end
diff --git a/test/wilcoxon.jl b/test/wilcoxon.jl
index cb3c716..f17a7ac 100644
--- a/test/wilcoxon.jl
+++ b/test/wilcoxon.jl
@@ -3,74 +3,74 @@ using HypothesisTests: default_tail
 
 @testset "Wilcoxon" begin
 @testset "Basic exact test" begin
-	@test abs(pvalue(ExactSignedRankTest([1:10;], [2:2:20;])) - 0.0020) <= 1e-4
-	@test abs(pvalue(ExactSignedRankTest([2:2:20;], [1:10;])) - 0.0020) <= 1e-4
-	@test abs(pvalue(ExactSignedRankTest([1:10;], [2:2:16; -1; 1])) - 0.4316) <= 1e-4
-	@test abs(pvalue(ExactSignedRankTest([2:2:16; -1; 1], [1:10;])) - 0.4316) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest([1:10;], [2:2:20;]))) - 0.0020) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest([2:2:20;], [1:10;]))) - 0.0020) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest([1:10;], [2:2:16; -1; 1]))) - 0.4316) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest([2:2:16; -1; 1], [1:10;]))) - 0.4316) <= 1e-4
 	@test default_tail(ExactSignedRankTest([1:10;], [2:2:20;])) == :both
 	show(IOBuffer(), ExactSignedRankTest([1:10;], [2:2:20;]))
 end
 
 @testset "Exact with ties" begin
-	@test abs(pvalue(ExactSignedRankTest([1:10;], [1:10;])) - 1) <= 1e-4
-	@test abs(pvalue(ExactSignedRankTest([1:10;], [2:11;])) - 0.0020) <= 1e-4
-	@test abs(pvalue(ExactSignedRankTest([2:11;], [1:10;])) - 0.0020) <= 1e-4
-	@test abs(pvalue(ExactSignedRankTest(1:10, [1:5; ones(5)])) - 0.0625) <= 1e-4
-	@test abs(pvalue(ExactSignedRankTest([1:5; ones(5)], [1:10;])) - 0.0625) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest([1:10;], [1:10;]))) - 1) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest([1:10;], [2:11;]))) - 0.0020) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest([2:11;], [1:10;]))) - 0.0020) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest(1:10, [1:5; ones(5)]))) - 0.0625) <= 1e-4
+    @test abs(@inferred(pvalue(ExactSignedRankTest([1:5; ones(5)], [1:10;]))) - 0.0625) <= 1e-4
 	show(IOBuffer(), ExactSignedRankTest([1:10;], [1:10;]))
 end
 
 @testset "Approximate test" begin
-	@test abs(pvalue(ApproximateSignedRankTest([1:10;], [2:2:20;])) - 0.005922) <= 1e-6
-	@test abs(pvalue(ApproximateSignedRankTest([2:2:20;], [1:10;])) - 0.005922) <= 1e-6
-	@test abs(pvalue(ApproximateSignedRankTest([1:10;], [2:2:16; -1; 1])) - 0.4148) <= 1e-4
-	@test abs(pvalue(ApproximateSignedRankTest([2:2:16; -1; 1], [1:10;])) - 0.4148) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([1:10;], [2:2:20;]))) - 0.005922) <= 1e-6
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([2:2:20;], [1:10;]))) - 0.005922) <= 1e-6
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([1:10;], [2:2:16; -1; 1]))) - 0.4148) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([2:2:16; -1; 1], [1:10;]))) - 0.4148) <= 1e-4
 	@test default_tail(ApproximateSignedRankTest([1:10;], [2:2:20;])) == :both
 	show(IOBuffer(), ApproximateSignedRankTest([1:10;], [2:2:20;]))
 end
 
 @testset "Approximate with ties" begin
-	@test abs(pvalue(ApproximateSignedRankTest([1:10;], [1:10;])) - 1) <= 1e-4
-	@test abs(pvalue(ApproximateSignedRankTest([1:10;], [2:11;])) - 0.001904) <= 1e-6
-	@test abs(pvalue(ApproximateSignedRankTest([2:11;], [1:10;])) - 0.001904) <= 1e-6
-	@test abs(pvalue(ApproximateSignedRankTest([1:10;], [1:5; ones(5)])) - 0.05906) <= 1e-5
-	@test abs(pvalue(ApproximateSignedRankTest([1:5; ones(5)], 1:10)) - 0.05906) <= 1e-5
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([1:10;], [1:10;]))) - 1) <= 1e-4
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([1:10;], [2:11;]))) - 0.001904) <= 1e-6
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([2:11;], [1:10;]))) - 0.001904) <= 1e-6
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([1:10;], [1:5; ones(5)]))) - 0.05906) <= 1e-5
+    @test abs(@inferred(pvalue(ApproximateSignedRankTest([1:5; ones(5)], 1:10))) - 0.05906) <= 1e-5
 	show(IOBuffer(), ApproximateSignedRankTest([1:10;], [1:10;]))
 end
 
 @testset "Tests for automatic selection" begin
-	@test abs(pvalue(SignedRankTest([1:10;], [2:2:20;])) - 0.0020) <= 1e-4
-	@test abs(pvalue(SignedRankTest([1:10;], [2:11;])) - 0.0020) <= 1e-4
+    @test abs(@inferred(pvalue(SignedRankTest([1:10;], [2:2:20;]))) - 0.0020) <= 1e-4
+    @test abs(@inferred(pvalue(SignedRankTest([1:10;], [2:11;]))) - 0.0020) <= 1e-4
 	@test default_tail(SignedRankTest([1:10;], [2:2:20;])) == :both
 	show(IOBuffer(), SignedRankTest([1:10;], [2:2:20;]))
 end
 
 @testset "One Sample tests" begin
 	# P-value computed using R wilcox.test
-	@test abs(pvalue(SignedRankTest([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] .- 10.1)) - 0.09460449) <= 1e-4
+    @test abs(@inferred(pvalue(SignedRankTest([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] .- 10.1))) - 0.09460449) <= 1e-4
 	# P-value computed using R wilcox.test
-	@test abs(pvalue(SignedRankTest([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] .- 10.1)) - 0.1928101) <= 1e-4
+    @test abs(@inferred(pvalue(SignedRankTest([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] .- 10.1))) - 0.1928101) <= 1e-4
 end
 
 @testset "One Sample tests with ties" begin
 	# P-value computed using R package exactRankTests wilcox.exact
-	@test abs(pvalue(SignedRankTest([1,2,3,4,5,6,7,10,10,10,10,10,13,14,15] .- 10.1)) - 0.04052734) <= 1e-4
+    @test abs(@inferred(pvalue(SignedRankTest([1,2,3,4,5,6,7,10,10,10,10,10,13,14,15] .- 10.1))) - 0.04052734) <= 1e-4
 	# P-value computed using R wilcox.test
-	@test abs(pvalue(SignedRankTest([1,2,3,4,5,6,7,10,10,10,10,10,13,14,15,16] .- 10.1)) - 0.1021964) <= 1e-4
+    @test abs(@inferred(pvalue(SignedRankTest([1,2,3,4,5,6,7,10,10,10,10,10,13,14,15,16] .- 10.1))) - 0.1021964) <= 1e-4
 end
 
 @testset "Issue 128" begin
-	@test pvalue(SignedRankTest([54.5, 54.5, 95.0, 51.5]), tail=:left)  == 1
-	@test pvalue(SignedRankTest([54.5, 54.5, 95.0, 51.5]), tail=:right) == 0.0625
+    @test @inferred(pvalue(SignedRankTest([54.5, 54.5, 95.0, 51.5]), tail=:left))  == 1
+    @test @inferred(pvalue(SignedRankTest([54.5, 54.5, 95.0, 51.5]), tail=:right)) == 0.0625
 end
 
 @testset "Test confidence interval" begin
-x = [-7.8, -6.9, -4.7, 3.7, 6.5, 8.7, 9.1, 10.1, 10.8, 13.6, 14.4, 16.6, 20.2, 22.4, 23.5]
-	@test isapprox(confint(ExactSignedRankTest(x))[1], 3.3, atol=1e-4)
-	@test isapprox(confint(ExactSignedRankTest(x))[2], 15.5, atol=1e-4)
-	@test isapprox(confint(ApproximateSignedRankTest(x))[1], 3.3, atol=1e-4)
-	@test isapprox(confint(ApproximateSignedRankTest(x))[2], 15.5, atol=1e-4)
-	@test isapprox(confint(SignedRankTest(x); tail=:left)[1], 4.45, atol=1e-4)
-	@test isapprox(confint(SignedRankTest(x); tail=:right)[2], 14.45, atol=1e-4)
+    x = [-7.8, -6.9, -4.7, 3.7, 6.5, 8.7, 9.1, 10.1, 10.8, 13.6, 14.4, 16.6, 20.2, 22.4, 23.5]
+    @test isapprox(@inferred(confint(ExactSignedRankTest(x)))[1], 3.3, atol=1e-4)
+    @test isapprox(@inferred(confint(ExactSignedRankTest(x)))[2], 15.5, atol=1e-4)
+    @test isapprox(@inferred(confint(ApproximateSignedRankTest(x)))[1], 3.3, atol=1e-4)
+    @test isapprox(@inferred(confint(ApproximateSignedRankTest(x)))[2], 15.5, atol=1e-4)
+    @test isapprox(@inferred(confint(SignedRankTest(x); tail=:left))[1], 4.45, atol=1e-4)
+    @test isapprox(@inferred(confint(SignedRankTest(x); tail=:right))[2], 14.45, atol=1e-4)
 end
 end