diff --git a/.travis.yml b/.travis.yml index fff4a8e5..91f7d89b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ language: julia os: - linux julia: - - 0.6 - 0.7 + - 1.0 - nightly notifications: email: false @@ -13,5 +13,5 @@ notifications: # - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi # - julia -e 'Pkg.clone(pwd()); Pkg.build("HypothesisTests"); Pkg.test("HypothesisTests"; coverage=true)' after_success: - - julia -e 'cd(Pkg.dir("HypothesisTests")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; - - julia -e 'Pkg.add("Documenter"); cd(Pkg.dir("HypothesisTests")); include(joinpath("docs", "make.jl"))' + - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'; + - julia -e 'using Pkg; Pkg.add("Documenter"); include(joinpath("docs", "make.jl"))' diff --git a/REQUIRE b/REQUIRE index 43e97d04..00891c56 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,7 +1,6 @@ -julia 0.6 -Distributions 0.10.0 +julia 0.7 +Distributions 0.16.3 Roots -StatsBase 0.9.0 -Compat 0.62.0 -Rmath 0.1.2 -Combinatorics +StatsBase 0.25.0 +Rmath 0.5.0 +Combinatorics 0.7.0 diff --git a/docs/make.jl b/docs/make.jl index bbc2466a..03b15a0d 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -16,7 +16,7 @@ makedocs( deploydocs( repo = "github.com/JuliaStats/HypothesisTests.jl.git", target = "build", - julia = "0.6", + julia = "1.0", deps = nothing, make = nothing ) diff --git a/src/HypothesisTests.jl b/src/HypothesisTests.jl index e5c4eab2..b36bb16d 100644 --- a/src/HypothesisTests.jl +++ b/src/HypothesisTests.jl @@ -22,12 +22,10 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -__precompile__() - module HypothesisTests -using Compat.Random, Compat.LinearAlgebra -using Distributions, Roots, StatsBase, Compat +using Statistics, Random, LinearAlgebra +using Distributions, Roots, StatsBase using Combinatorics: combinations, permutations using Rmath: pwilcox, psignrank @@ -112,7 +110,7 @@ function Base.show(io::IO, test::T) where T<:HypothesisTest println(io, " value under h_0: $param_under_h0") println(io, " point estimate: $param_estimate") if has_ci - ci = map(x -> Compat.round.(x, digits=4, base=10), StatsBase.confint(test)) + ci = map(x -> round.(x, digits=4, base=10), StatsBase.confint(test)) println(io, " 95% confidence interval: $ci") end println(io) diff --git a/src/anderson_darling.jl b/src/anderson_darling.jl index 85898b8d..fb2f3d1a 100644 --- a/src/anderson_darling.jl +++ b/src/anderson_darling.jl @@ -264,7 +264,7 @@ function adkvals(Z⁺, N, samples) fij[i, searchsortedfirst(Z⁺, s)] += 1 end end - ljs = Compat.sum(fij, dims=1) + ljs = sum(fij, dims=1) A²k = A²km = 0. for i in 1:k diff --git a/src/durbin_watson.jl b/src/durbin_watson.jl index 5312ae8b..60e38fd7 100644 --- a/src/durbin_watson.jl +++ b/src/durbin_watson.jl @@ -22,10 +22,6 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -if VERSION < v"0.7.0-DEV.4591" - tr(A::AbstractMatrix) = trace(A) -end - export DurbinWatsonTest struct DurbinWatsonTest <: HypothesisTest @@ -197,7 +193,7 @@ function pvalue(x::DurbinWatsonTest; tail=:both) if p_temp < 0.0 || p_temp > 1.0 # println(p_temp) - Compat.@warn("Exact p-values outside [0,1]. Approximate p-values reported instead.") + @warn("Exact p-values outside [0,1]. Approximate p-values reported instead.") exact_problem_flag = 1 end end diff --git a/src/kolmogorov_smirnov.jl b/src/kolmogorov_smirnov.jl index fb2af4e0..78684702 100644 --- a/src/kolmogorov_smirnov.jl +++ b/src/kolmogorov_smirnov.jl @@ -65,7 +65,7 @@ Implements: [`pvalue`](@ref) """ function ExactOneSampleKSTest(x::AbstractVector{T}, d::UnivariateDistribution) where T<:Real if length(x) > length(unique(x)) - Compat.@warn("This test is inaccurate with ties") + @warn("This test is inaccurate with ties") end ExactOneSampleKSTest(ksstats(x, d)...) @@ -109,7 +109,7 @@ Implements: [`pvalue`](@ref) """ function ApproximateOneSampleKSTest(x::AbstractVector{T}, d::UnivariateDistribution) where T<:Real if length(x) > length(unique(x)) - Compat.@warn("This test is inaccurate with ties") + @warn("This test is inaccurate with ties") end ApproximateOneSampleKSTest(ksstats(x, d)...) @@ -164,7 +164,7 @@ Implements: [`pvalue`](@ref) function ApproximateTwoSampleKSTest(x::AbstractVector{T}, y::AbstractVector{S}) where {T<:Real, S<:Real} n_x, n_y = length(x), length(y) if n_x+n_y > length(unique([x; y])) - Compat.@warn("This test is inaccurate with ties") + @warn("This test is inaccurate with ties") end ApproximateTwoSampleKSTest(ksstats(x, y)...) diff --git a/src/kruskal_wallis.jl b/src/kruskal_wallis.jl index a045318a..a98aff04 100644 --- a/src/kruskal_wallis.jl +++ b/src/kruskal_wallis.jl @@ -70,7 +70,7 @@ Implements: [`pvalue`](@ref) function KruskalWallisTest(groups::AbstractVector{T}...) where T<:Real (H, R_i, tieadj, n_i) = kwstats(groups...) if length(groups)<=3 && any(n_i .< 6) - Compat.@warn("This test is only asymptotically correct and might be inaccurate for the given group size") + @warn("This test is only asymptotically correct and might be inaccurate for the given group size") end df = length(groups) - 1 KruskalWallisTest(n_i, df, R_i, H, tieadj) diff --git a/src/power_divergence.jl b/src/power_divergence.jl index 20d9cd51..94e8be11 100644 --- a/src/power_divergence.jl +++ b/src/power_divergence.jl @@ -97,7 +97,7 @@ end # Bootstrap function ci_bootstrap(x::PowerDivergenceTest,alpha::Float64, iters::Int64) - m = Compat.mapslices(x -> quantile(x, [alpha / 2, 1 - alpha / 2]), rand(Multinomial(x.n, convert(Vector{Float64}, x.thetahat)),iters) / x.n, dims=2) + m = mapslices(x -> quantile(x, [alpha / 2, 1 - alpha / 2]), rand(Multinomial(x.n, convert(Vector{Float64}, x.thetahat)),iters) / x.n, dims=2) Tuple{Float64,Float64}[(boundproportion(m[i,1]), boundproportion(m[i,2])) for i in 1:length(x.thetahat)] end @@ -285,8 +285,8 @@ function PowerDivergenceTest(x::AbstractMatrix{T}; lambda::U=1.0, theta0::Vector (!isfinite(nrows) || !isfinite(ncols) || !isfinite(nrows*ncols)) && throw(ArgumentError("invalid number of rows or columns")) if nrows > 1 && ncols > 1 - rowsums = Compat.sum(x, dims=2) - colsums = Compat.sum(x, dims=1) + rowsums = sum(x, dims=2) + colsums = sum(x, dims=1) df = (nrows - 1) * (ncols - 1) thetahat = x ./ n xhat = rowsums * colsums / n diff --git a/test/anderson_darling.jl b/test/anderson_darling.jl index d7a35fab..f0823660 100644 --- a/test/anderson_darling.jl +++ b/test/anderson_darling.jl @@ -1,87 +1,86 @@ -using HypothesisTests, Distributions, Compat.Test +using HypothesisTests, Distributions, Test, Random using HypothesisTests: default_tail -using Compat.Random @testset "Anderson-Darling" begin @testset "One sample test" begin - n = 1000 - srand(1984948) - - x = rand(Normal(), n) - t = OneSampleADTest(x, Normal()) - @test t.A² ≈ 0.2013 atol=0.1^4 - @test pvalue(t) ≈ 0.99 atol=0.1^4 - @test default_tail(t) == :right - - x = rand(DoubleExponential(), n) - t = OneSampleADTest(x, Normal()) - @test t.A² ≈ 10.7439 atol=0.1^4 - @test pvalue(t) ≈ 0.0 atol=0.1^4 - - x = rand(Cauchy(), n) - t = OneSampleADTest(x, Normal()) - @test pvalue(t) ≈ 0.0 atol=0.1^4 - - x = rand(LogNormal(), n) - t = OneSampleADTest(x, Normal()) - @test pvalue(t) ≈ 0.0 atol=0.1^4 - - x = rand(Uniform(), n) - t = OneSampleADTest(x, Uniform()) - @test pvalue(t) ≈ 0.145 atol=0.1^4 - - x = rand(Uniform(0, 1.8), n) - t = OneSampleADTest(x, Uniform()) - @test pvalue(t) ≈ 0.5112 atol=0.1^4 - - x = rand(Exponential(), n) - t = OneSampleADTest(x, Exponential()) - @test pvalue(t) ≈ 0.9427 atol=0.1^4 + n = 1000 + Random.seed!(1984948) + + x = rand(Normal(), n) + t = OneSampleADTest(x, Normal()) + @test t.A² ≈ 0.2013 atol=0.1^4 + @test pvalue(t) ≈ 0.99 atol=0.1^4 + @test default_tail(t) == :right + + x = rand(DoubleExponential(), n) + t = OneSampleADTest(x, Normal()) + @test t.A² ≈ 10.7439 atol=0.1^4 + @test pvalue(t) ≈ 0.0 atol=0.1^4 + + x = rand(Cauchy(), n) + t = OneSampleADTest(x, Normal()) + @test pvalue(t) ≈ 0.0 atol=0.1^4 + + x = rand(LogNormal(), n) + t = OneSampleADTest(x, Normal()) + @test pvalue(t) ≈ 0.0 atol=0.1^4 + + x = rand(Uniform(), n) + t = OneSampleADTest(x, Uniform()) + @test pvalue(t) ≈ 0.145 atol=0.1^4 + + x = rand(Uniform(0, 1.8), n) + t = OneSampleADTest(x, Uniform()) + @test pvalue(t) ≈ 0.5112 atol=0.1^4 + + x = rand(Exponential(), n) + t = OneSampleADTest(x, Exponential()) + @test pvalue(t) ≈ 0.9427 atol=0.1^4 end @testset "k-sample test" begin - srand(948574875) - samples = Any[ - [38.7, 41.5, 43.8, 44.5, 45.5, 46.0, 47.7, 58.0], - [39.2, 39.3, 39.7, 41.4, 41.8, 42.9, 43.3, 45.8], - [34.0, 35.0, 39.0, 40.0, 43.0, 43.0, 44.0, 45.0], - [34.0, 34.8, 34.8, 35.4, 37.2, 37.8, 41.2, 42.8] - ] - - t = KSampleADTest(samples...) - @test t.A²k ≈ 8.3926 atol=0.1^4 - @test t.σ ≈ 1.2038 atol=0.1^4 - @test pvalue(t) ≈ 0.0022 atol=0.1^4 - @test default_tail(t) == :right - - ts = KSampleADTest(samples..., nsim = 20000); - @test pvalue(ts) ≈ 0.00155 atol=0.1^3 - - t = KSampleADTest(samples..., modified = false) - @test t.A²k ≈ 8.3559 atol=0.1^4 - @test t.σ ≈ 1.2038 atol=0.1^4 - @test pvalue(t) ≈ 0.0023 atol=0.1^4 - - ts = KSampleADTest(samples..., modified = false, nsim = 20000); - @test pvalue(ts) ≈ 0.00150 atol=0.1^3 + Random.seed!(948574875) + samples = Any[ + [38.7, 41.5, 43.8, 44.5, 45.5, 46.0, 47.7, 58.0], + [39.2, 39.3, 39.7, 41.4, 41.8, 42.9, 43.3, 45.8], + [34.0, 35.0, 39.0, 40.0, 43.0, 43.0, 44.0, 45.0], + [34.0, 34.8, 34.8, 35.4, 37.2, 37.8, 41.2, 42.8] + ] + + t = KSampleADTest(samples...) + @test t.A²k ≈ 8.3926 atol=0.1^4 + @test t.σ ≈ 1.2038 atol=0.1^4 + @test pvalue(t) ≈ 0.0022 atol=0.1^4 + @test default_tail(t) == :right + + ts = KSampleADTest(samples..., nsim = 20000); + @test pvalue(ts) ≈ 0.00155 atol=0.1^3 + + t = KSampleADTest(samples..., modified = false) + @test t.A²k ≈ 8.3559 atol=0.1^4 + @test t.σ ≈ 1.2038 atol=0.1^4 + @test pvalue(t) ≈ 0.0023 atol=0.1^4 + + ts = KSampleADTest(samples..., modified = false, nsim = 20000); + @test pvalue(ts) ≈ 0.00150 atol=0.1^3 end @testset "more tests" begin - srand(31412455) - samples = Any[rand(Normal(), 50), rand(Normal(0.5), 30)] - t = KSampleADTest(samples...) - @test pvalue(t) < 0.05 + Random.seed!(31412455) + samples = Any[rand(Normal(), 50), rand(Normal(0.5), 30)] + t = KSampleADTest(samples...) + @test pvalue(t) < 0.05 - samples = Any[rand(Normal(), 50), rand(Normal(), 30), rand(Normal(), 20)] - t = KSampleADTest(samples...) - @test pvalue(t) > 0.05 + samples = Any[rand(Normal(), 50), rand(Normal(), 30), rand(Normal(), 20)] + t = KSampleADTest(samples...) + @test pvalue(t) > 0.05 - @test pvalue(OneSampleADTest(vcat(rand(Normal(),500), rand(Beta(2,2),500)), Beta(2,2))) ≈ 0.0 atol=0.1^4 + @test pvalue(OneSampleADTest(vcat(rand(Normal(),500), rand(Beta(2,2),500)), Beta(2,2))) ≈ 0.0 atol=0.1^4 - n = 1000 - x = rand(Exponential(), n) - @test pvalue(KSampleADTest(rand(1000),randn(1000))) ≈ 0.0 atol=eps() - @test pvalue(KSampleADTest(x,x,x,x,x,x)) ≈ 1.0 + n = 1000 + x = rand(Exponential(), n) + @test pvalue(KSampleADTest(rand(1000),randn(1000))) ≈ 0.0 atol=eps() + @test pvalue(KSampleADTest(x,x,x,x,x,x)) ≈ 1.0 end end diff --git a/test/augmented_dickey_fuller.jl b/test/augmented_dickey_fuller.jl index 8e6f54c9..059bfa8d 100644 --- a/test/augmented_dickey_fuller.jl +++ b/test/augmented_dickey_fuller.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.LinearAlgebra, Compat.Test +using HypothesisTests, LinearAlgebra, Test @testset "Augmented Dickey-Fuller" begin sim_data_h0 = [ diff --git a/test/binomial.jl b/test/binomial.jl index 665347ce..1509df00 100644 --- a/test/binomial.jl +++ b/test/binomial.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Binomial" begin diff --git a/test/box_test.jl b/test/box_test.jl index 3fef734b..2f507071 100644 --- a/test/box_test.jl +++ b/test/box_test.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Box-Pierce and Ljung-Box" begin diff --git a/test/breusch_godfrey.jl b/test/breusch_godfrey.jl index ddf9a438..ad7ae480 100644 --- a/test/breusch_godfrey.jl +++ b/test/breusch_godfrey.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Breusch-Godfrey" begin diff --git a/test/circular.jl b/test/circular.jl index d7c2db30..05431d16 100644 --- a/test/circular.jl +++ b/test/circular.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Circular" begin diff --git a/test/common.jl b/test/common.jl index 9d20fd8b..f1269863 100644 --- a/test/common.jl +++ b/test/common.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test mutable struct TestTest <: HypothesisTests.HypothesisTest end diff --git a/test/durbin_watson.jl b/test/durbin_watson.jl index dc903385..fd891836 100644 --- a/test/durbin_watson.jl +++ b/test/durbin_watson.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Durbin-Watson" begin diff --git a/test/fisher.jl b/test/fisher.jl index 2dab1dfa..30e9fb79 100644 --- a/test/fisher.jl +++ b/test/fisher.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Fisher" begin diff --git a/test/jarque_bera.jl b/test/jarque_bera.jl index 0ce93774..4c92c7cb 100644 --- a/test/jarque_bera.jl +++ b/test/jarque_bera.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Jarque-Bera" begin diff --git a/test/kolmogorov_smirnov.jl b/test/kolmogorov_smirnov.jl index e6e710d3..584d3ca1 100644 --- a/test/kolmogorov_smirnov.jl +++ b/test/kolmogorov_smirnov.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Distributions, Compat.Test +using HypothesisTests, Distributions, Test @testset "Kolmogorov-Smirnov" begin # sample drawn from uniform distribution diff --git a/test/kruskal_wallis.jl b/test/kruskal_wallis.jl index 6c7ec557..7e47c32c 100644 --- a/test/kruskal_wallis.jl +++ b/test/kruskal_wallis.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Kruskal-Wallis" begin diff --git a/test/mann_whitney.jl b/test/mann_whitney.jl index 63ee043e..68e4ec09 100644 --- a/test/mann_whitney.jl +++ b/test/mann_whitney.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Mann-Whitney" begin diff --git a/test/permutation.jl b/test/permutation.jl index afcff4c0..c232c465 100644 --- a/test/permutation.jl +++ b/test/permutation.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test @testset "Permutation" begin @test isapprox(pvalue(ExactPermutationTest([1,2,3],[4,5,6],mean), tail=:both), 1.0) @@ -6,7 +6,7 @@ using HypothesisTests, Compat.Test @test isapprox(pvalue(ExactPermutationTest([1,2,3],[4,5,6],mean), tail=:left), 0.05) @test isapprox(pvalue(ExactPermutationTest([4,5,6],[1,2,3],mean), tail=:right), 0.05) -srand(12345) +Random.seed!(12345) @test isapprox(pvalue(ApproximatePermutationTest([1,2,3],[4,5,6],mean,100), tail=:both), 1.0) @test isapprox(pvalue(ApproximatePermutationTest([4,5,6],[1,2,3],mean,100), tail=:both), 1.0) @test isapprox(pvalue(ApproximatePermutationTest([1,2,3],[4,5,6],mean,100), tail=:left), 0.08) diff --git a/test/power_divergence.jl b/test/power_divergence.jl index 797980be..83107a21 100644 --- a/test/power_divergence.jl +++ b/test/power_divergence.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using StatsBase using HypothesisTests: default_tail diff --git a/test/runtests.jl b/test/runtests.jl index 28d4bc65..4cc4277d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,13 +1,14 @@ -using Compat +using Test, Random, Statistics + # Confidence intervals should be tested component-wise against # expected results; splatting them into arrays and checking for # approximate array equality is incorrect when either limit is # infinite. macro test_ci_approx(x::Expr, y::Expr) return quote - Compat.Test.@test typeof($(esc(x))) <: Tuple{Real,Real} - Compat.Test.@test typeof($(esc(x))) == typeof($(esc(y))) - Compat.Test.@test all(map(isapprox, $(esc(x)), $(esc(y)))) + Test.@test typeof($(esc(x))) <: Tuple{Real,Real} + Test.@test typeof($(esc(x))) == typeof($(esc(y))) + Test.@test all(map(isapprox, $(esc(x)), $(esc(y)))) end end diff --git a/test/show.jl b/test/show.jl index 2c6cb75c..6626c13d 100644 --- a/test/show.jl +++ b/test/show.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test @testset "Show" begin # based on power_divergence.jl tests diff --git a/test/t.jl b/test/t.jl index b76f87a5..340bc624 100644 --- a/test/t.jl +++ b/test/t.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "T-test" begin diff --git a/test/wilcoxon.jl b/test/wilcoxon.jl index 5e247d39..cb3c7163 100644 --- a/test/wilcoxon.jl +++ b/test/wilcoxon.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using HypothesisTests: default_tail @testset "Wilcoxon" begin diff --git a/test/z.jl b/test/z.jl index 9f69659b..749c8d48 100644 --- a/test/z.jl +++ b/test/z.jl @@ -1,4 +1,4 @@ -using HypothesisTests, Compat.Test +using HypothesisTests, Test using Distributions using HypothesisTests: default_tail