JuliaStats / StatsFuns.jl

Mathematical functions related to statistics.
Other
235 stars 40 forks source link

`fdistccdf` errors instead of returning 0.0 #134

Closed matthieugomez closed 2 years ago

matthieugomez commented 2 years ago

On StatsFuns v0.9.15, fdistccdf(1, 100000, 10000.0) used to return 0.0. On v0.9.16, it now returns an error:

fdistccdf(1, 100000, 10000.0)
ERROR: expansion can't be computed
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] beta_inc_asymptotic_asymmetric(a::Float64, b::Float64, x::Float64, y::Float64, w::Float64, epps::Float64)
   @ SpecialFunctions ~/.julia/packages/SpecialFunctions/rNt4H/src/beta_inc.jl:384
 [3] _beta_inc(a::Float64, b::Float64, x::Float64, y::Float64)
   @ SpecialFunctions ~/.julia/packages/SpecialFunctions/rNt4H/src/beta_inc.jl:865
 [4] _beta_inc
   @ ~/.julia/packages/SpecialFunctions/rNt4H/src/beta_inc.jl:736 [inlined]
 [5] beta_inc
   @ ~/.julia/packages/SpecialFunctions/rNt4H/src/beta_inc.jl:729 [inlined]
 [6] betaccdf
   @ ~/.julia/packages/StatsFuns/dTYga/src/distrs/beta.jl:44 [inlined]
 [7] fdistccdf(ν1::Float64, ν2::Float64, x::Float64)
   @ StatsFuns ~/.julia/packages/StatsFuns/dTYga/src/distrs/fdist.jl:18
 [8] fdistccdf(ν1::Int64, ν2::Int64, x::Float64)
   @ StatsFuns ~/.julia/packages/StatsFuns/dTYga/src/distrs/fdist.jl:19
 [9] top-level scope
   @ REPL[13]:1

This error makes GLM fit fail in certain cases

matthieugomez commented 2 years ago

Probably linked to https://github.com/JuliaMath/SpecialFunctions.jl/issues/334

devmotion commented 2 years ago

Yes, this is https://github.com/JuliaMath/SpecialFunctions.jl/issues/334 which was exposed here due to our partial switch from Rmath to Julia implementations based on SpecialFunctions in 0.9.16. fdistccdf(1, 100_000, 10_000) ends up calling betaccdf(0.5, 50_000, 1/11) which is computed as last(SpecialFunctions.beta_inc(0.5, 50_000, 1/11)).

devmotion commented 2 years ago

Until the upstream bug in SpecialFunctions is fixed, probably the easiest solution is to pin StatsFuns to 0.9.15.

matthieugomez commented 2 years ago

This creates errors in downstream packages: https://github.com/FixedEffects/FixedEffectModels.jl/issues/192

Is it possible to remove the tag 0.9.16 instead? (and maybe use 0.10)

andreasnoack commented 2 years ago

I've made a PR with a patch. We might be able to release it later today.

andreasnoack commented 2 years ago

Should be fixed with https://github.com/JuliaRegistries/General/pull/55444. Please report back if you still experience problems downsrteam.

matthieugomez commented 2 years ago

Thanks a lot!