stats
stats copied to clipboard
qinvgamma returns nan
For some inputs (apparently close to 1), qinvgamma
is returning nan
.
Example:
stats::qinvgamma(0.999551553841898, 2.0, 1.0)
Probably the result of overflow?
I was able to fix the issue by tracing the nan
back to the incomplete_gamma_inv
function in GCEM.
In the file gcem/include/gcem_incl/incomplete_gamma_inv.hpp
changing
...
incomplete_gamma_inv_halley(const T ratio_val_1, const T ratio_val_2)
noexcept
{
return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) );
}
to
...
incomplete_gamma_inv_halley(const T ratio_val_1, const T ratio_val_2)
noexcept
{
return( ratio_val_1 / ( T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) );
}
recovers the correct result. All tests pass, although I'm not completely sure why the safeguards were there in the first place.