我试图从python的《时序分析》一书中复制一个示例,不仅我没有得到相同的平滑形状,而且我仅看到不稳定的行为。我检查了我是否在编码错误(例如参数),但似乎找不到任何解决方案。有任何提示吗?
这是我试图复制的R中的示例,摘自《时间序列分析》,Chan和Cryer 2008:
我尝试使用statsmodels:
import matplotlib.pyplot as plt
import statsmodels.api as sm
from statsmodels.graphics import tsaplots
fig, ax = plt.subplots(2,2, figsize=(10, 10), sharey=True, sharex=True)
for n, i in enumerate([[0.5,0.25], [1, -0.25], [1.5, -0.75], [1, -0.6]]):
y = sm.tsa.arma_generate_sample(ar=[1]+[-j in i for j in i], ma=[1, 0], nsample=100)
tsaplots.plot_acf(y, ax[n//2][n%2], lags=20, fft=True)#lags=len(y)//2)
if n//2: ax[n//2][n%2].set_xlabel('Lag [t]')
if n in [0,2]: ax[n//2][n%2].set_ylabel(r'Correlation [$\rho$]')
ax[n//2][n%2].legend(['AR(2)={}'.format(i)])
plt.show()
输出: