@@ -84,7 +84,10 @@ Series B (Statistical Methodology) 66, 187–205.
8484struct 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
8891end
8992
9093Storey () = 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
136142end
137143
138144StoreyBootstrap () = 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
150156end
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
211217end
@@ -229,7 +235,10 @@ julia> estimate_pi0(pvals, Oracle(0.5)) # a bit boring...
229235struct 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
233242end
234243
235244Oracle () = 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
273285end
274286
275287TwoStep () = TwoStep (0.05 )
@@ -313,8 +325,10 @@ Statistical Society: Series B (Statistical Methodology) 74, 163–182.
313325struct 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
318332end
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
336350end
@@ -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
375389end
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
504517end
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
629641end
630642
@@ -713,11 +725,11 @@ function convex_decreasing(pValues::AbstractVector{T},
713725end
714726
715727function 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] )
717729end
718730
719731function 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] )
721733end
722734
723735function decide (f_p:: Vector{Float64} , f_theta_p:: Vector{Float64} , ε:: Float64 )
0 commit comments