Skip to content

Commit

Permalink
fix(arima): handle zero sigma2 in CSS method (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewscottm authored Dec 20, 2024
1 parent 4a5cb06 commit 9d0ea52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion nbs/src/arima.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,10 @@
" fit['xreg'] = xreg\n",
" npar = fit['mask'].sum() + 1\n",
" if method == 'CSS':\n",
" fit['aic'] = offset + nstar * math.log(fit['sigma2']) + 2 * npar\n",
" if fit['sigma2'] <= 0:\n",
" fit['aic'] = -math.inf\n",
" else:\n",
" fit['aic'] = offset + nstar * math.log(fit['sigma2']) + 2 * npar\n",
" if not math.isnan(fit['aic']):\n",
" fit['bic'] = fit['aic'] + npar * (math.log(nstar) - 2)\n",
" if nstar - npar - 1 != 0:\n",
Expand Down
5 changes: 4 additions & 1 deletion python/statsforecast/arima.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,10 @@ def myarima(
fit["xreg"] = xreg
npar = fit["mask"].sum() + 1
if method == "CSS":
fit["aic"] = offset + nstar * math.log(fit["sigma2"]) + 2 * npar
if fit["sigma2"] <= 0:
fit["aic"] = -math.inf
else:
fit["aic"] = offset + nstar * math.log(fit["sigma2"]) + 2 * npar
if not math.isnan(fit["aic"]):
fit["bic"] = fit["aic"] + npar * (math.log(nstar) - 2)
if nstar - npar - 1 != 0:
Expand Down

0 comments on commit 9d0ea52

Please sign in to comment.