Skip to content

Commit 1be88de

Browse files
Merge pull request #99 from juliangehring/julia-v0.7
Support for julia v0.7
2 parents 20f206d + 8f0a156 commit 1be88de

21 files changed

+85
-74
lines changed

.appveyor.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
4-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
54

65
matrix:
76
fast_finish: true
8-
allow_failures:
9-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
107

118
notifications:
129
- provider: Email

.travis.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ os:
44
- linux
55

66
julia:
7-
- 0.6
8-
- nightly
7+
- 0.7
98

109
matrix:
1110
fast_finish: true
12-
allow_failures:
13-
- julia: nightly
1411

1512
notifications:
1613
email:
@@ -23,5 +20,4 @@ script:
2320

2421
after_success:
2522
- julia -e 'cd(Pkg.dir("MultipleTesting")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder(), flags="julia_$(VERSION.major)_$(VERSION.minor)")'
26-
- julia -e 'Pkg.add("Documenter")'
27-
- julia -e 'cd(Pkg.dir("MultipleTesting")); include(joinpath("docs", "make.jl"))'
23+
- julia -e 'cd(Pkg.dir("MultipleTesting")); Pkg.add("Documenter"); include(joinpath("docs", "make.jl"))'

REQUIRE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.6
2-
StatsBase 0.15.0
3-
Distributions 0.14.1
1+
julia 0.7
2+
StatsBase 0.24.0
3+
Distributions 0.16.1
44
SpecialFunctions 0.3.8

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ makedocs(
2424

2525
deploydocs(
2626
repo = "github.com/juliangehring/MultipleTesting.jl.git",
27-
julia = "0.6",
27+
julia = "0.7",
2828
target = "build",
2929
deps = nothing,
3030
make = nothing

src/MultipleTesting.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import Distributions: estimate
1717

1818
import SpecialFunctions: digamma
1919

20+
import Random: shuffle!
21+
2022
export
2123
PValues,
2224
adjust,

src/combinations.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function combine(pValues::PValues{T}, method::StoufferCombination)::T where T<:A
166166
if minimum(pValues) == 0 || maximum(pValues) == 1
167167
return NaN
168168
end
169-
z = cquantile.(Normal(), pValues)
169+
z = cquantile.(Ref(Normal()), pValues)
170170
z = sum(z) ./ sqrt(n)
171171
p = ccdf(Normal(), z)
172172
return p
@@ -180,7 +180,7 @@ function combine(pValues::PValues{T}, weights::AbstractVector{R}, method::Stouff
180180
if minimum(pValues) == 0 || maximum(pValues) == 1
181181
return NaN
182182
end
183-
z = cquantile.(Normal(), pValues) .* weights
183+
z = cquantile.(Ref(Normal()), pValues) .* weights
184184
z = sum(z) ./ sqrt(sum(abs2, weights))
185185
p = ccdf(Normal(), z)
186186
return p
@@ -307,7 +307,7 @@ function combine(pValues::PValues{T}, method::WilkinsonCombination)::T where T<:
307307
if rank < 1 || rank > n
308308
throw(ArgumentError("Rank must be in 1,..,$(n)"))
309309
end
310-
p_rank = select(pValues, rank) # faster than `sort(pValues)[rank]`
310+
p_rank = partialsort(pValues, rank)
311311
p = cdf(Beta(rank, n-rank+1), p_rank)
312312
return p
313313
end

src/higher-criticism.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function estimate(pValues::PValues{T}, method::HigherCriticismScores) where T<:A
3636
denom = F .* (one(T) .- F) ./ n
3737
# avoid denominator of 0 for last value
3838
idx0 = denom .== 0
39-
denom[idx0] = minimum(denom[.!idx0]) .+ eps() # conservative
39+
denom[idx0] .= minimum(denom[.!idx0]) .+ eps() # conservative
4040
hcs = abs.(F .- pValues) ./ sqrt.(denom)
4141
return hcs
4242
end
@@ -68,6 +68,6 @@ struct HigherCriticismThreshold
6868
end
6969

7070
function estimate(pValues::PValues{T}, method::HigherCriticismThreshold) where T<:AbstractFloat
71-
idx_hcv = indmax(estimate(pValues, HigherCriticismScores()))
71+
idx_hcv = argmax(estimate(pValues, HigherCriticismScores()))
7272
return pValues[idx_hcv]
7373
end

src/model.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ partitioning the empirical distribution of p-values. Bioinformatics 19,
4343
4444
"""
4545
function BetaUniformMixtureModel(π0::AbstractFloat, α::AbstractFloat = 0.5, β::AbstractFloat = 1.0)
46-
if !isin(π0, 0., 1.)
47-
throw(DomainError())
48-
end
49-
MixtureModel([Beta(α, β), Uniform()], [1-π0, π0])
46+
isin(π0, 0, 1) || throw(DomainError("π0 must be in [0, 1]"))
47+
bum = MixtureModel([Beta(α, β), Uniform()], [1-π0, π0])
48+
return bum
5049
end

src/pi0-estimators.jl

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ Series B (Statistical Methodology) 66, 187–205.
8484
struct Storey <: Pi0Estimator
8585
λ::Float64
8686

87-
Storey(λ) = isin(λ, 0, 1) ? new(λ) : throw(DomainError())
87+
function Storey(λ)
88+
isin(λ, 0, 1) || throw(DomainError("λ must be in [0, 1]"))
89+
return new(λ)
90+
end
8891
end
8992

9093
Storey() = Storey(0.1)
@@ -131,8 +134,11 @@ struct StoreyBootstrap <: Pi0Estimator
131134
λseq::Vector{Float64}
132135
q ::Float64
133136

134-
StoreyBootstrap(λseq, q) =
135-
isin(λseq, 0, 1) && isin(q, 0, 1) ? new(λseq, q) : throw(DomainError())
137+
function StoreyBootstrap(λseq, q)
138+
isin(λseq, 0, 1) || throw(DomainError("λseq must be in [0, 1]"))
139+
isin(q, 0, 1) || throw(DomainError("q must be in [0, 1]"))
140+
return new(λseq, q)
141+
end
136142
end
137143

138144
StoreyBootstrap() = StoreyBootstrap(0.05:0.05:0.95, 0.1)
@@ -145,7 +151,7 @@ function estimate_pi0(pValues::PValues{T}, pi0estimator::StoreyBootstrap) where
145151
pi0 = w ./ n ./ (1 .- lambdas)
146152
min_pi0 = quantile(pi0, q)
147153
mse = (w ./ (n.^2 .* (1 .- lambdas).^2 )) .* (1 .- w/n) + (pi0 .- min_pi0).^2
148-
pi0 = clamp(pi0[indmin(mse)], 0, 1)
154+
pi0 = clamp(pi0[argmin(mse)], 0, 1)
149155
return pi0
150156
end
151157

@@ -205,7 +211,7 @@ function lsl_pi0_vec(pValues::AbstractVector{T}) where T<:AbstractFloat
205211
pValues = sort_if_needed(pValues)
206212
s = (1 .- pValues) ./ (n:-1:1)
207213
d = diff(s) .< 0
208-
idx = findfirst(d) + 1
214+
idx = something(findfirst(d), 0) + 1
209215
pi0 = min( 1/s[idx] + 1, n ) / n
210216
return pi0
211217
end
@@ -229,7 +235,10 @@ julia> estimate_pi0(pvals, Oracle(0.5)) # a bit boring...
229235
struct Oracle <: Pi0Estimator
230236
π0::Float64
231237

232-
Oracle(π0) = isin(π0, 0, 1) ? new(π0) : throw(DomainError())
238+
function Oracle(π0)
239+
isin(π0, 0, 1) || throw(DomainError("π0 must be in [0, 1]"))
240+
return new(π0)
241+
end
233242
end
234243

235244
Oracle() = Oracle(1.0)
@@ -269,7 +278,10 @@ struct TwoStep <: Pi0Estimator
269278
α::Float64
270279
adjustment::PValueAdjustment
271280

272-
TwoStep(α, method) = isin(α, 0, 1) ? new(α, method) : throw(DomainError())
281+
function TwoStep(α, method)
282+
isin(α, 0, 1) || throw(DomainError("α must be in [0, 1]"))
283+
return new(α, method)
284+
end
273285
end
274286

275287
TwoStep() = TwoStep(0.05)
@@ -313,8 +325,10 @@ Statistical Society: Series B (Statistical Methodology) 74, 163–182.
313325
struct RightBoundary <: Pi0Estimator
314326
λseq::Vector{Float64}
315327

316-
RightBoundary(λseq) =
317-
isin(λseq, 0, 1) ? new(λseq) : throw(DomainError())
328+
function RightBoundary(λseq)
329+
isin(λseq, 0, 1) || throw(DomainError("λseq must be in [0, 1]"))
330+
return new(λseq)
331+
end
318332
end
319333

320334
# λseq used in Liang, Nettleton 2012
@@ -330,7 +344,7 @@ function estimate_pi0(pValues::PValues{T}, pi0estimator::RightBoundary) where T<
330344
pi0_estimates = reverse(cumsum(reverse(h.weights)))./(1 .- λseq)./n
331345
pi0_decrease = diff(pi0_estimates) .>= 0
332346
pi0_decrease[end] = true
333-
pi0 = pi0_estimates[findfirst(pi0_decrease, true) + 1]
347+
pi0 = pi0_estimates[something(findfirst(pi0_decrease), 0) + 1]
334348
pi0 = clamp(pi0, 0, 1)
335349
return pi0
336350
end
@@ -366,11 +380,11 @@ struct CensoredBUM <: Pi0Estimator
366380
maxiter::Int64
367381

368382
function CensoredBUM(γ0, λ, xtol, maxiter)
369-
if isin(γ0, 0, 1) && isin(λ, 0, 1) && isin(xtol, 0, 1) && maxiter > 0
370-
new(γ0, λ, xtol, maxiter)
371-
else
372-
throw(DomainError())
373-
end
383+
isin(γ0, 0, 1) || throw(DomainError("γ0 must be in [0, 1]"))
384+
isin(λ, 0, 1) || throw(DomainError("λ must be in [0, 1]"))
385+
isin(xtol, 0, 1) || throw(DomainError("xtol must be in [0, 1]"))
386+
maxiter > 0 || throw(DomainError("maxiter must be a positive number"))
387+
return new(γ0, λ, xtol, maxiter)
374388
end
375389
end
376390

@@ -451,7 +465,7 @@ function cbum_pi0_naive(pValues::AbstractVector{T},
451465
α = -sum(z[idx_right])
452466
α = α / ( ll * sum(z[idx_left]) + sum(z[idx_right] .* lpr) )
453467
xl = (1-γ) *^α)
454-
z[idx_left] = xl ./*λ + xl)
468+
z[idx_left] .= xl /*λ + xl)
455469
xr = (1-γ) * α * pValues[idx_right].^-1)
456470
z[idx_right] = xr ./.+ xr)
457471
pi0_new = γ + (1-γ)*α
@@ -495,11 +509,10 @@ struct BUM <: Pi0Estimator
495509
maxiter::Int64
496510

497511
function BUM(γ0, xtol, maxiter)
498-
if isin(γ0, 0, 1) && isin(xtol, 0, 1)
499-
new(γ0, xtol, maxiter)
500-
else
501-
throw(DomainError())
502-
end
512+
isin(γ0, 0, 1) || throw(DomainError("γ0 must be in [0, 1]"))
513+
isin(xtol, 0, 1) || throw(DomainError("xtol must be in [0, 1]"))
514+
maxiter > 0 || throw(DomainError("maxiter must be a positive number"))
515+
return new(γ0, xtol, maxiter)
503516
end
504517
end
505518

@@ -620,11 +633,10 @@ struct ConvexDecreasing <: Pi0Estimator
620633
maxiter::Int64
621634

622635
function ConvexDecreasing(gridsize, xtol, maxiter)
623-
if gridsize > 0 && isin(xtol, 0, 1) && maxiter > 0
624-
new(gridsize, xtol, maxiter)
625-
else
626-
throw(DomainError())
627-
end
636+
gridsize > 0 || throw(DomainError("gridsize must be a positive number"))
637+
isin(xtol, 0, 1) || throw(DomainError("xtol must be in [0, 1]"))
638+
maxiter > 0 || throw(DomainError("maxiter must be a positive number"))
639+
return new(gridsize, xtol, maxiter)
628640
end
629641
end
630642

@@ -713,11 +725,11 @@ function convex_decreasing(pValues::AbstractVector{T},
713725
end
714726

715727
function find_theta(t::Vector{Float64}, p::Vector{Float64})
716-
return indmax( [theta.^-2 * sum(theta .- p[p .< theta]) for theta in t] )
728+
return argmax( [theta.^-2 * sum(theta .- p[p .< theta]) for theta in t] )
717729
end
718730

719731
function find_theta(t::Vector{Float64}, p::Vector{Float64}, f_p::Vector{Float64})
720-
return indmax( [theta.^-2 * sum( (theta .- p) .* (p .< theta) ./ f_p ) for theta in t] )
732+
return argmax( [theta.^-2 * sum( (theta .- p) .* (p .< theta) ./ f_p ) for theta in t] )
721733
end
722734

723735
function decide(f_p::Vector{Float64}, f_theta_p::Vector{Float64}, ε::Float64)

src/pval-adjustment.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,4 @@ function check_number_tests(k::Integer, n::Integer)
726726
end
727727

728728

729-
harmonic_number(n::Integer) = digamma(n+1) + γ
729+
harmonic_number(n::Integer) = digamma(n+1) + MathConstants.γ

0 commit comments

Comments
 (0)