Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 查找时间序列问题的acf值时出现的问题_Python_R_Time Series - Fatal编程技术网

Python 查找时间序列问题的acf值时出现的问题

Python 查找时间序列问题的acf值时出现的问题,python,r,time-series,Python,R,Time Series,我试图在时间序列问题中找到acf的值。我有一个从2003年到2017年的数据集 我使用以下函数创建数据的时间序列 tf = ts(df$x, start = c(2003,1), end = c(2017,12), frequency = 12) 当我试图通过使用函数绘图来查找acf值时 acf(ts) 我的图表是这样的 在使用时间序列函数时,我无法得出‘p’的值应该是多少。因为图形显示没有反转 fit = arima(tf, c(p,2,3)) 作为参考,我的数据如下所示 我无法计算“

我试图在时间序列问题中找到acf的值。我有一个从2003年到2017年的数据集

我使用以下函数创建数据的时间序列

tf = ts(df$x, start = c(2003,1), end = c(2017,12), frequency = 12)
当我试图通过使用函数绘图来查找acf值时

acf(ts)
我的图表是这样的

在使用时间序列函数时,我无法得出‘p’的值应该是多少。因为图形显示没有反转

fit = arima(tf, c(p,2,3))
作为参考,我的数据如下所示


我无法计算“p”应该使用什么值。我也尝试了不同的“p”值,范围在1到20之间,但预测值不是很准确。任何帮助都将不胜感激。

要计算p,请使用PACF,而不是ACF


不过,只需使用R中forecast包中的auto.arima函数就容易多了,它会自动为您找到最佳的p、q、d值

首先,我要用时间序列的差来表示它,它有一个相当大的随机趋势。这方面最明显的迹象是,除了时间序列稳步上升外,ACF组件需要很长时间才能消失。虽然可以使用漂移项将模型与数据进行拟合,但当趋势不存在时,读取ACF和PACF图要容易得多

tf <- structure(c(58082, 48500, 45723, 53662, 46723, 45070, 49782, 55437,
57672, 61121, 43857, 49819, 50750, 53589, 53812, 53575, 52339, 51115,
56529, 61498, 58757, 72876, 55999, 58374, 63885, 63287, 60027, 65795,
62850, 61908, 68108, 72639, 77105, 84996, 65488, 62178, 74750, 66085,
59711, 69304, 68357, 67133, 74545, 73623, 82071, 89533, 72117, 69004,
72681, 80214, 80744, 81643, 87599, 86213, 97495, 97841, 104953, 110353,
90415, 83875, 93160, 89539, 85021, 91314, 87036, 83731, 91047, 94552,
105628, 94743, 84954, 72535, 77898, 68418, 60609, 73703, 67298, 64375,
73550, 76887, 77538, 92233, 73267, 77779, 80634, 72736, 81475, 87595,
87386, 88874, 95145, 96991, 95186, 106122, 81173, 77941, 88576, 86372,
77850, 91188, 90547, 87803, 95264, 90054, 100544, 96302, 82402, 78297,
91847, 86235, 87557, 91139, 93116, 93855, 94172, 100003, 97051, 86785,
84849, 81682, 88273, 85645, 80121, 92187, 96409, 97609, 94971, 111356,
102049, 110838, 97596, 88747, 100882, 97801, 99312, 100163, 112241, 101667,
122227, 127548, 123216, 131987, 112248, 118140, 128127, 114529, 151671,
135476, 148513, 141155, 142314, 142144, 139774, 142715, 124773, 111401,
129554, 140624, 128378, 130208, 141051, 132299, 145779, 152341, 146552,
150930, 139732, 133423, 154363, 148374, 137392, 149258, 160086, 154738,
159570, 164496, 166885, 188369, 144181, 148121, 169758, 158890, 159699,
161691, 165828, 175617, 181875, 182883), .Tsp = c(1, 188, 1), class = "ts")

par(mfrow=c(3, 1), mar=c(3, 3, 2, 1), mgp=c(2, 0.6, 0), oma=c(0, 0, 0, 0))
plot(tf); acf(tf, main=""); pacf(tf, main="")
图5

如果我们分解tf.d12,我们将看到数据中还有一个微小的趋势。向模型中添加非季节性差异可能是合适的:

arima(tf.d12, order=c(2, 1, 1), seasonal=c(2, 1, 1))
分解还揭示了剩余部分的时间成分,其大小似乎随时间增加。我们的模型没有处理这个问题

tsoutliers::locate.outliers
表示索引145处的一个附加异常值,以及71和149处的两个时间变化


很抱歉,这有点冗长,我开始研究数据,无法停止。最后,这整件事可能更适合于这样的地方,那里也有很多知识渊博的人可以提出第二种意见。

@girijesh96:Duke大学的Rober Nau有一个非常全面和可读的资源。除此之外,阅读问题和答案通常是有用的。你说得很对,我们不能盲目相信auto-arima。我尝试了自动arima,但结果不是很令人信服,所以我放弃了自动arima的想法。是的,这是每月的数据。我还发现了同一指数上的两个异常值。我想知道你是如何得出这是一阶季节性差异成分的结论的。@girijesh96:在图3中,滞后1、2、3等的自相关衰减非常缓慢,这意味着每年1月的值与前一个1月的值相同,加上/减去一个小变化。这本质上是一个随机游走过程,一种非平稳的形式,通过将d或d设置为1来解释。将季节性订单设置为(2,0,0)也可以,但我认为这不能反映时间序列中发生的事情。好的,谢谢你的精彩解释和非常详细的回答。为了完全理解你的答案,我必须学习一些时间序列的概念。
tf.d12 <- ts(tf.d, f=12)
plot(tf.d12); acf(tf.d12, main="", lag.max=12*4); pacf(tf.d12, main="", lag.max=12*4)
ari1 <- arima(tf.d12, order=c(2, 0, 0), seasonal=c(2, 1, 0))
ari2 <- arima(tf.d12, order=c(1, 0, 1), seasonal=c(2, 1, 0))
ari3 <- arima(tf.d12, order=c(1, 0, 1), seasonal=c(2, 1, 1))

par(mfcol=c(3, 2), mar=c(3, 3, 2, 1), mgp=c(2, 0.6, 0), oma=c(0, 0, 1.5, 0))
acf(residuals(ari1), main="", ylim=c(-0.2, 1), lag.max=12*4)
mtext(ari1$call, 3, cex=0.8)
acf(residuals(ari2), main="", ylim=c(-0.2, 1), lag.max=12*4)
mtext(ari2$call, 3, cex=0.8)
acf(residuals(ari3), main="", ylim=c(-0.2, 1), lag.max=12*4)
mtext(ari3$call, 3, cex=0.8)
pacf(residuals(ari1), main="", ylim=c(-0.2, 0.44), lag.max=12*4)
mtext(ari1$call, 3, cex=0.8)
pacf(residuals(ari2), main="", ylim=c(-0.2, 0.44), lag.max=12*4)
mtext(ari2$call, 3, cex=0.8)
pacf(residuals(ari3), main="", ylim=c(-0.2, 0.44), lag.max=12*4)
mtext(ari3$call, 3, cex=0.8)
mtext("residual values", 3, outer=TRUE, cex=1.3)
par(mfrow=c(1, 1), mar=c(3, 3, 2, 1), mgp=c(2, 0.6, 0), oma=c(0, 0, 0, 0))
plot(stl(tf.d12, "periodic"))
arima(tf.d12, order=c(2, 1, 1), seasonal=c(2, 1, 1))