您需要fit
使用固定的参数进行调用。这是使用fix_params
上下文管理器完成的。首先是无约束模型。
from statsmodels.tsa.arima_process import ArmaProcess
from statsmodels.tsa.statespace.sarimax import SARIMAX
import numpy as np
# Simulate SARIMAX(1, 0, 1)x(1, 1, [], 10)
# AR: (1-L^10)(1-0.5L)(1-0.8L^10)
# MA: (1+0.6L)
np.random.seed(20220304)
ar = [0.5, 0, 0, 0, 0, 0, 0, 0, 0, 1.8, -0.9, 0, 0, 0, 0, 0, 0, 0, 0, -0.8, 0.4]
ma = [0.6]
ap = ArmaProcess.from_coeffs(ar,ma)
y = ap.generate_sample(4000)
model = SARIMAX(endog=y, order=[1,0,1], seasonal_order=[1, 1, 0, 10])
res = model.fit()
res.summary()
估计值非常接近用于生成样本的参数。
SARIMAX Results
===========================================================================================
Dep. Variable: y No. Observations: 4000
Model: SARIMAX(1, 0, 1)x(1, 1, [], 10) Log Likelihood -5574.986
Date: Fri, 04 Mar 2022 AIC 11157.971
Time: 10:18:45 BIC 11183.138
Sample: 0 HQIC 11166.893
- 4000
Covariance Type: opg
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
ar.L1 0.5258 0.016 31.888 0.000 0.493 0.558
ma.L1 0.5665 0.016 35.395 0.000 0.535 0.598
ar.S.L10 0.8070 0.009 87.185 0.000 0.789 0.825
sigma2 0.9547 0.021 45.938 0.000 0.914 0.995
===================================================================================
Ljung-Box (L1) (Q): 0.04 Jarque-Bera (JB): 3.46
Prob(Q): 0.83 Prob(JB): 0.18
Heteroskedasticity (H): 0.94 Skew: -0.04
Prob(H) (two-sided): 0.26 Kurtosis: 3.12
===================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
接下来,我们使用fix_params
withwith
关键字临时固定参数,然后fit
在上下文管理器内部调用。
with model.fix_params({'ma.L1': 0}):
con_res = model.fit()
con_res.summary()
这些参数不同,因为没有 MA。
SARIMAX Results
===========================================================================================
Dep. Variable: y No. Observations: 4000
Model: SARIMAX(1, 0, 1)x(1, 1, [], 10) Log Likelihood -5929.452
Date: Fri, 04 Mar 2022 AIC 11864.904
Time: 10:18:29 BIC 11883.779
Sample: 0 HQIC 11871.595
- 4000
Covariance Type: opg
=================================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------------
ar.L1 0.7409 0.011 68.937 0.000 0.720 0.762
ma.L1 (fixed) 0 nan nan nan nan nan
ar.S.L10 0.8087 0.009 88.918 0.000 0.791 0.826
sigma2 1.1404 0.025 44.983 0.000 1.091 1.190
===================================================================================
Ljung-Box (L1) (Q): 256.27 Jarque-Bera (JB): 1.90
Prob(Q): 0.00 Prob(JB): 0.39
Heteroskedasticity (H): 0.92 Skew: -0.05
Prob(H) (two-sided): 0.11 Kurtosis: 3.03
===================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
请注意,您使用的限制将模型减少到 MA(0),因此最好0
在 MA 滞后长度中重新指定模型。
pure_ar_model = SARIMAX(endog=y, order=[1,0,0], seasonal_order=[1, 1, 0, 10])
pure_ar_res = pure_ar_model.fit()
pure_ar_res.summary()
这些参数将估计值与固定参数相匹配。
SARIMAX Results
==========================================================================================
Dep. Variable: y No. Observations: 4000
Model: SARIMAX(1, 0, 0)x(1, 1, 0, 10) Log Likelihood -5929.452
Date: Fri, 04 Mar 2022 AIC 11864.904
Time: 10:18:13 BIC 11883.779
Sample: 0 HQIC 11871.595
- 4000
Covariance Type: opg
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
ar.L1 0.7409 0.011 68.937 0.000 0.720 0.762
ar.S.L10 0.8087 0.009 88.920 0.000 0.791 0.827
sigma2 1.1404 0.025 44.983 0.000 1.091 1.190
===================================================================================
Ljung-Box (L1) (Q): 256.27 Jarque-Bera (JB): 1.90
Prob(Q): 0.00 Prob(JB): 0.39
Heteroskedasticity (H): 0.92 Skew: -0.05
Prob(H) (two-sided): 0.11 Kurtosis: 3.03
===================================================================================