首页 > 解决方案 > 时间序列分析:如何在python中绘制这些AR(1)图?

问题描述

AR(1) 的方程为:

在此处输入图像描述

案例:

在此处输入图像描述

这是它的样子: 在此处输入图像描述

所以我想出了这个代码:

from random import gauss
from random import seed
from matplotlib import pyplot
seed(1)
N = 100
b1 = [1, 0.8]
b2 = [1, -0.8]
b3 = [0.1, 1]
b4 = [0, 1.1]
sigma1to2 = 0.1
sigma3to4 = 0.5
e1to2 = [gauss(0, sigma1to2) for i in range(N)]
e3to4 = [gauss(0, sigma3to4) for i in range(N)]

x1 = np.zeros(N)
x2 = np.zeros(N)
x3 = np.zeros(N)
x4 = np.zeros(N)
for i in range(1,N):
    x1[i] = b1[0] + (b1[1]* x1[i-1]) + e1to2[i]
    x2[i] = b2[0] + (b2[1]* x2[i-1]) + e1to2[i]
    x3[i] = b3[0] + (b3[1]* x3[i-1]) + e3to4[i]
    x4[i] = b4[0] + (b4[1]* x4[i-1]) + e3to4[i]
fig = plt.figure(figsize=(15,5))
plt.subplot(221)
plt.plot(x1,label='series1')
plt.title('series1')
plt.subplot(222)
plt.plot(x2,label='series2')
plt.title('series2')
plt.subplot(223)
plt.plot(x3,label='series3')
plt.title('series3')
plt.subplot(224)
plt.plot(x4,label='series4')
plt.title('series4')
plt.show()

这就是我得到的: 在此处输入图像描述

我做错了什么?第一张和最后一张图与该图不匹配。实际上,我在绘制图表后找出了 ACF,并且在某些情况下 ACF 会根据这三个参数值而有所不同。在我的情况下,第一个和最后一个案例的 ACF 会有所不同。因此,我无法正确概括这些案例。

标签: pythonstatisticstime-seriesarima

解决方案


我只需要将 xlimit 和起始函数值更改为非零。


推荐阅读