python - 时间序列分析:如何在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 会有所不同。因此,我无法正确概括这些案例。
解决方案
我只需要将 xlimit 和起始函数值更改为非零。
推荐阅读
- html - 在 godaddy 上托管的网站有时会停止加载
- ios - 在我的应用中控制其他应用的音乐
- python - RuntimeError:对象没有属性 nms:
- git - 修复非顺序提交
- angular8 - 无法从 Angular 8 下载 excel 文件,服务器端代码是 .net core webapi 3.1
- jquery - 我需要删除类等于 attr 输入的“li”
- regex - 每次{}之间的数据不匹配某些数据时,如何在一个组中匹配某些数据以及{}之间的正则表达式和颤振?
- c++ - “模拟”部分功能模板专业化?
- google-bigquery - 带有参数的 Google Data Studio 和 BigQuery 自定义 SQL
- css - 为什么这个 CSS 会给出验证错误?