Skip to content

Commit

Permalink
Merge pull request statsmodels#7093 from bashtage/theta-pred-err-fix
Browse files Browse the repository at this point in the history
BUG: Correct prediction intervals for ThetaModel
  • Loading branch information
bashtage committed Oct 11, 2020
2 parents 4a95e14 + c7d9699 commit 52b142c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions statsmodels/tsa/forecasting/tests/test_theta.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,15 @@ def test_forecast_errors(data):
res.forecast(7, theta=0.99)
with pytest.raises(ValueError, match="steps must be a positive integer"):
res.forecast_components(0)


def test_pi_width():
# GH 7075
rs = np.random.RandomState(1233091)
y = np.arange(100) + rs.standard_normal(100)

th = ThetaModel(y, period=12, deseasonalize=False)
res = th.fit()
pi = res.prediction_intervals(24)
d = np.squeeze(np.diff(np.asarray(pi), axis=1))
assert np.all(np.diff(d) > 0)
10 changes: 6 additions & 4 deletions statsmodels/tsa/forecasting/theta.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,13 @@ def prediction_intervals(
-----
The variance of the h-step forecast is assumed to follow from the
integrated Moving Average structure of the Theta model, and so is
:math:`\sigma^2(\alpha^2 + (h-1))`. The prediction interval assumes
that innovations are normally distributed.
:math:`\sigma^2(1 + (h-1)(1 + (\alpha-1)^2)`. The prediction interval
assumes that innovations are normally distributed.
"""
model_alpha = self.params[0]
sigma2_h = model_alpha ** 2 + np.arange(steps) * self.sigma2
model_alpha = self.params[1]
sigma2_h = (
1 + np.arange(steps) * (1 + (model_alpha - 1) ** 2)
) * self.sigma2
sigma_h = np.sqrt(sigma2_h)
quantile = stats.norm.ppf(alpha / 2)
predictions = self.forecast(steps, theta)
Expand Down

0 comments on commit 52b142c

Please sign in to comment.