python - 时间序列分析:How to plot these AR(1) graphs in python?

标签 python statistics time-series arima

AR(1) 的方程为:

enter image description here

案例:

enter image description here

它是这样的: enter image description here

所以我想出了这段代码:

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()

这就是我得到的: enter image description here

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

最佳答案

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

关于python - 时间序列分析:How to plot these AR(1) graphs in python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53237362/

相关文章:

python - 我怎样才能在 pymysql 中开始交易? (mysql)

python - 同时计算 2 列的扩展平均值

python - 使用带有错误的距离矩阵*查找点的坐标

R Holt Winters 分解错误 'no or less than 2 periods'

python - python 匹配txt文件中的字符串并获取它旁边的数字

python - 通过 OpenFaaS 在 Kubernetes 中部署 FastAPI 微服务

Python - 查找每个可能的单词对在文本文件的同一行中出现的频率的最有效方法?

asp.net - html 页面的 ASP 服务器统计信息

r - 如何将 15 分钟的数据转换为日期时间格式的时间序列,以便我可以使用 quantmod 绘制它?

r - 如何合并连续两年的冬季月份