Skip to content

v1.1.3 — Critical MLE Bug Fixes & Numerical Corrections

Choose a tag to compare

@evandeilton evandeilton released this 21 May 00:35
· 10 commits to main since this release

What's Changed

Critical Bug Fixes

  • llgkw() invalid parameter return — fixed returning R_NegInf instead of R_PosInf for invalid parameters. Gradient-based MLE optimizers treat −∞ as a global minimum, causing silent convergence to invalid boundaries.
  • gkwinit delta=0 rejectiongkw_pdf() incorrectly rejected delta = 0 (valid for EKw, Kw sub-families) due to a strict delta <= 0 guard that should have been delta < 0.
  • gkwinit EKw/Kw sub-family mappingekw_pdf() and kw_pdf() passed delta = 1 instead of the correct delta = 0, producing wrong starting values for MLE of these families.
  • hsbkw() Hessian error for β < 1 — ternary expression (beta > 1.0) ? v_beta/v : 1.0 returned 1.0 for all β ≤ 1, yielding wrong second derivatives and incorrect standard errors when β ∈ (0, 1).

Numerical Corrections

  • safe_exp() 10× scaling error — moderate-underflow branch computed 10 × exp(x) instead of exp(x) due to use of DBL_MIN_SAFE = 10 × DBL_MIN in the scaling expression.
  • dgkw() silent boundary truncation removed — a block silently returned density = 0 for valid data near x = 0 or x = 1 without warning; removed since log-space arithmetic handles these values correctly.
  • llekw() / grekw() lambda clamping removed — arbitrary min(lambda_factor, 1000) cap distorted gradients and Hessians for λ > 1000.

Code Quality

  • Hessian accumulation in hsgkw() / hsekw() refactored to build upper triangle only and symmetrize once with arma::symmatu().
  • Removed spurious try/catch blocks in grbkw() / hsbkw() around Rcpp::as<arma::vec> conversions that cannot throw.
  • Removed using namespace Rcpp; from gkwinit.cpp; added NA/NaN filtering before moment computation.
  • Added UB guard in vec_safe_pow() for static_cast<int> when exponent > INT_MAX.
  • Added SIMD-friendly fast path arma::exp(y * arma::log(x)) in vec_safe_pow() for the common case (y > 0, all x > 0).

Build

R CMD check --as-cran: 0 errors | 0 warnings | 0 notes
Tests: 342/342 pass