估计模型阶数:PACF
识别 AR 模型阶数的一个有用工具是查看偏自相关函数(Partial Autocorrelation Function,PACF)。在本练习中,您将模拟两条时间序列:一条 AR(1) 和一条 AR(2),并分别计算各自的样本 PACF。您会发现,对于 AR(1),PACF 在滞后 1 上应当显著,此后大致为 0;而对于 AR(2),样本 PACF 在滞后 1 和滞后 2 上应当显著,此后为 0。
与之前练习中使用 plot_acf 函数类似,这里您将使用 statsmodels 模块中的 plot_pacf 函数。
本练习是课程的一部分
Python 中的时间序列分析
练习说明
- 导入用于模拟数据和绘制 PACF 的模块。
- 模拟一个 AR(1),令 $\small \phi=0.6$(注意 AR 参数的符号在实现中需要取反)。
- 使用
plot_pacf为simulated_data_1绘制 PACF 图。 - 模拟一个 AR(2),令 \(\small \phi_1=0.6, \phi_2=0.3\)(同样需要将符号取反)。
- 使用
plot_pacf为simulated_data_2绘制 PACF 图。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the modules for simulating data and for plotting the PACF
from statsmodels.tsa.arima_process import ArmaProcess
from statsmodels.graphics.tsaplots import plot_pacf
# Simulate AR(1) with phi=+0.6
ma = np.array([1])
ar = np.array([1, -0.6])
AR_object = ArmaProcess(ar, ma)
simulated_data_1 = ___.generate_sample(nsample=5000)
# Plot PACF for AR(1)
plot_pacf(___, lags=20)
plt.show()
# Simulate AR(2) with phi1=+0.6, phi2=+0.3
ma = np.array([1])
ar = np.array([1, ___, ___])
AR_object = ArmaProcess(ar, ma)
simulated_data_2 = ___.generate_sample(nsample=5000)
# Plot PACF for AR(2)
plot_pacf(___, lags=20)
plt.show()