Skip to content

Commit

Permalink
Updates for Julia 1.0 (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored Sep 3, 2018
1 parent 82321ac commit be0aefc
Show file tree
Hide file tree
Showing 29 changed files with 115 additions and 122 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ language: julia
os:
- linux
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
Expand All @@ -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"))'
11 changes: 5 additions & 6 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
8 changes: 3 additions & 5 deletions src/HypothesisTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/anderson_darling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions src/durbin_watson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/kolmogorov_smirnov.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)...)
Expand Down Expand Up @@ -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)...)
Expand Down Expand Up @@ -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)...)
Expand Down
2 changes: 1 addition & 1 deletion src/kruskal_wallis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/power_divergence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
141 changes: 70 additions & 71 deletions test/anderson_darling.jl
Original file line number Diff line number Diff line change
@@ -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. 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. 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. 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. 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
2 changes: 1 addition & 1 deletion test/augmented_dickey_fuller.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.LinearAlgebra, Compat.Test
using HypothesisTests, LinearAlgebra, Test

@testset "Augmented Dickey-Fuller" begin
sim_data_h0 = [
Expand Down
2 changes: 1 addition & 1 deletion test/binomial.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Binomial" begin
Expand Down
2 changes: 1 addition & 1 deletion test/box_test.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Box-Pierce and Ljung-Box" begin
Expand Down
2 changes: 1 addition & 1 deletion test/breusch_godfrey.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Breusch-Godfrey" begin
Expand Down
2 changes: 1 addition & 1 deletion test/circular.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Circular" begin
Expand Down
2 changes: 1 addition & 1 deletion test/common.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test

mutable struct TestTest <: HypothesisTests.HypothesisTest end

Expand Down
2 changes: 1 addition & 1 deletion test/durbin_watson.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Durbin-Watson" begin
Expand Down
2 changes: 1 addition & 1 deletion test/fisher.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Fisher" begin
Expand Down
2 changes: 1 addition & 1 deletion test/jarque_bera.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Jarque-Bera" begin
Expand Down
2 changes: 1 addition & 1 deletion test/kolmogorov_smirnov.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Distributions, Compat.Test
using HypothesisTests, Distributions, Test

@testset "Kolmogorov-Smirnov" begin
# sample drawn from uniform distribution
Expand Down
2 changes: 1 addition & 1 deletion test/kruskal_wallis.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Kruskal-Wallis" begin
Expand Down
2 changes: 1 addition & 1 deletion test/mann_whitney.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using HypothesisTests: default_tail

@testset "Mann-Whitney" begin
Expand Down
4 changes: 2 additions & 2 deletions test/permutation.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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)
@test isapprox(pvalue(ExactPermutationTest([4,5,6],[1,2,3],mean), tail=:both), 1.0)
@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)
Expand Down
2 changes: 1 addition & 1 deletion test/power_divergence.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HypothesisTests, Compat.Test
using HypothesisTests, Test
using StatsBase
using HypothesisTests: default_tail

Expand Down
Loading

0 comments on commit be0aefc

Please sign in to comment.