Skip to content

Commit 303f10e

Browse files
authored
Merge pull request statsmodels#6133 from ChadFulton/statsmodelsgh-6127
BUG: start_params for VMA model with exog.
2 parents a588a44 + b263bf5 commit 303f10e

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

statsmodels/tsa/statespace/tests/test_varmax.py

+45-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import pandas as pd
1414
import pytest
1515

16-
from statsmodels.tsa.statespace import varmax
16+
from statsmodels.tsa.statespace import varmax, sarimax
1717
from statsmodels.iolib.summary import forg
1818

1919
from .results import results_varmax
@@ -1129,3 +1129,47 @@ def test_apply_results():
11291129

11301130
assert_allclose(res3.forecast(10, exog=np.ones(10)),
11311131
res1.forecast(10, exog=np.ones(10)))
1132+
1133+
1134+
def test_vma1_exog():
1135+
# Test the VMAX(1) case against univariate MAX(1) models
1136+
dta = pd.DataFrame(
1137+
results_varmax.lutkepohl_data, columns=['inv', 'inc', 'consump'],
1138+
index=pd.date_range('1960-01-01', '1982-10-01', freq='QS'))
1139+
dta = np.log(dta).diff().iloc[1:]
1140+
1141+
endog = dta.iloc[:, :2]
1142+
exog = dta.iloc[:, 2]
1143+
1144+
ma_params1 = [-0.01, 1.4, -0.3, 0.002]
1145+
ma_params2 = [0.004, 0.8, -0.5, 0.0001]
1146+
1147+
vma_params = [ma_params1[0], ma_params2[0],
1148+
ma_params1[2], 0,
1149+
0, ma_params2[2],
1150+
ma_params1[1], ma_params2[1],
1151+
ma_params1[3], ma_params2[3]]
1152+
1153+
# Joint VMA model
1154+
mod_vma = varmax.VARMAX(endog, exog=exog, order=(0, 1),
1155+
error_cov_type='diagonal')
1156+
mod_vma.ssm.initialize_diffuse()
1157+
res_mva = mod_vma.smooth(vma_params)
1158+
1159+
# Smoke test that start_params doesn't raise an error
1160+
sp = mod_vma.start_params
1161+
assert_equal(len(sp), len(mod_vma.param_names))
1162+
1163+
# Univariate MA models
1164+
mod_ma1 = sarimax.SARIMAX(endog.iloc[:, 0], exog=exog, order=(0, 0, 1),
1165+
trend='c')
1166+
mod_ma1.ssm.initialize_diffuse()
1167+
mod_ma2 = sarimax.SARIMAX(endog.iloc[:, 1], exog=exog, order=(0, 0, 1),
1168+
trend='c')
1169+
mod_ma2.ssm.initialize_diffuse()
1170+
res_ma1 = mod_ma1.smooth(ma_params1)
1171+
res_ma2 = mod_ma2.smooth(ma_params2)
1172+
1173+
# Have to ignore first 2 observations due to differences in initialization
1174+
assert_allclose(res_mva.llf_obs[2:],
1175+
(res_ma1.llf_obs + res_ma2.llf_obs)[2:])

statsmodels/tsa/statespace/varmax.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def start_params(self):
392392
ma_params *= 0
393393

394394
# Transform trend / exog params from mean form to intercept form
395-
if self.k_ar > 0 and self.k_trend > 0 or self.mle_regression:
395+
if self.k_ar > 0 and (self.k_trend > 0 or self.mle_regression):
396396
coefficient_matrices = (
397397
ar_params.reshape(
398398
self.k_endog * self.k_ar, self.k_endog

0 commit comments

Comments
 (0)