通过在时间序列预测中执行差分来消除趋势

时间:2014-07-19 14:52:31

标签: time-series prediction difference trend

在文献的基础上,对于时间相关性建模,应该从时间序列数据中去除趋势。我们选择差分来消除趋势。

我想知道:

当我们执行差异时,数据完全改变,随后预测将被改变。 例如,如果我们假设数据范围是7.9,7.25,6.98和......,那么在执行差分后,预测将低于1。 我们应该如何评估现实世界数据中的预测? 我们是否应该对参考数据执行类似的差分?

我正在使用AR(p)时间模型。此外,该过程在R软件中实现。

Data sample(rn25_29_o):

class = c("POSIXct", 
"POSIXt"), tzone = "")), .Names = c("ambtemp", "dt"), row.names = c(NA, 
486L), class = "data.frame")

  ambtemp                  dt
1   -1.96 2007-09-28 23:55:00
2   -2.02 2007-09-28 23:57:00
3   -1.92 2007-09-28 23:59:00
4   -1.64 2007-09-29 00:01:00
5   -1.76 2007-09-29 00:03:00
6   -1.83 2007-09-29 00:05:00

dput(Dif_Median_ambtemp) 
structure(c(NA, 0.2, 0.16, -0.0700000000000001, -0.1, -0.04, 
-0.01, 0, 0.0700000000000001, 0.23, 0.16, -0.26, -0.3, -0.18, 
0, -0.04, -0.04, 0.14, 0.14, 0.14, -0.02, -0.0999999999999999, 
0, 0.16, 0.0900000000000001, 0.28, 0.27, -0.17, -0.17, 0, -0.02, 
-0.12, -0.1, 0, -0.05, -0.0800000000000001, -0.0699999999999998, 
0, 0.03, -0.00999999999999979, 0, 0.0999999999999999, 0.0999999999999999, 
0.0800000000000001, 0.12, 0.24, 0.26, 0.0999999999999999, 0.0599999999999998, 
0.02, 0, -0.02, -0.0599999999999998, -0.0399999999999998, 0, 
0, -0.02, -0.0700000000000001, -0.24, -0.37, -0.22, -0.0799999999999998, 
-0.03, -0.12, -0.03, 0.1, 0.02, 0.14, 0.18, 0.0600000000000001, 
0, -0.02, -0.0600000000000001, -0.04, 0, -0.02, -0.0999999999999999, 
-0.11, -0.16, -0.13, 0.0800000000000001, 0.0800000000000001, 
0, 0.01, 0.12, 0, 0.22, 0.23, -0.1, -0.0800000000000001, -0.0800000000000001, 
0, 0, 0.02, 0.28, 0.3, 0.04, -0.0900000000000001, -0.0900000000000001, 
-0.01, -0.22, -0.37, -0.16, 0, -0.32, -0.45, -0.13, 0.04, 0.04, 
0, 0.1, 0.12, 0.0399999999999996, 0, 0, -0.12, 0, 0.14, 0.02, 
0, 0.02, 0.34, 0.3, -0.0800000000000001, -0.0900000000000001, 
-0.01, -0.01, -0.12, -0.11, 0, -0.17, -0.17, -0.16, -0.16, 0.24, 
0.24, 0.0900000000000003, 0.0900000000000003, 0, 0.11, 0.41, 
0.45, 0.27, 0, -0.15, -0.03, 0.0600000000000001, 0.0800000000000001, 
0.0600000000000001, 0.04, 0, -0.04, -0.0600000000000001, -0.14, 
-0.18, -0.0600000000000001, -0.01, -0.26, -0.32, -0.22, -0.15, 
0.12, 0.18, 0.0600000000000001, 0, 0.0800000000000001, 0, -0.11, 
-0.0299999999999998, 0.2, 0.33, 0.13, 0.0600000000000001, 0.0600000000000001, 
-0.01, -0.03, -0.15, -0.15, -0.0799999999999998, -0.0899999999999999, 
-0.04, -0.01, -0.01, -0.0600000000000001, -0.05, 0, 0.02, 0.05, 
0.18, 0.17, 0.05, 0.0800000000000001, 0.0600000000000001, 0.3, 
0.34, 0.0499999999999998, 0.02, 0.05, 0.03, -0.23, -0.48, -0.33, 
-0.13, -0.14, -0.11, -0.02, 0.04, 0.0800000000000001, 0.0800000000000001, 
0.13, 0.15, 0.0700000000000001, 0.01, -0.02, -0.0800000000000001, 
-0.0600000000000001, -0.04, -0.0799999999999998, -0.0499999999999998, 
-0.04, -0.03, -0.04, -0.0600000000000001, -0.02, 0.02, 0.04, 
0.04, 0.02, 0, 0, 0, 0, 0.02, 0.02, 0, 0.02, 0.0399999999999998, 
0.0199999999999998, 0, 0.14, 0.31, 0.19, 0.02, -0.01, -0.0700000000000001, 
-0.23, -0.2, -0.03, 0, -0.0799999999999998, -0.0799999999999998, 
0.44, 0.54, 0.0999999999999999, 0.1, 0.1, 0.26, 0.26, 0, 1.08, 
1.08, -0.24, -0.62, -0.44, -0.18, -0.02, 0, 0, 0.01, 0.16, 0.55, 
0.3, 0.26, 0.18, 0.18, 0.26, 0, -0.37, -0.37, 0.18, 0.41, 0.35, 
0.12, -0.73, -0.73, 0.07, 0.23, 0.16, -0.26, -0.26, 0.4, 0.4, 
0, 0.08, 1.1, 1.02, -0.27, -0.62, -0.84, -0.49, 0.19, 1.29, 1.12, 
0.62, 0.76, 0.48, 0.32, -0.82, -0.92, -0.17, -0.19, -0.33, -0.21, 
0, 0, 0.44, 0.98, 0.65, 0.11, -0.13, -0.13, -0.44, -0.89, -0.45, 
0.17, 0.17, 0.38, 0.4, 0.3, 0.16, 0, 0.5, 0.38, -0.22, -0.72, 
-0.65, 0, 0.38, 0.23, 0.0900000000000001, 0.25, 0.16, 0.66, 0.66, 
0, -1.09, -1.09, 0.17, 0.91, 0.8, 0.0599999999999996, 0, -0.21, 
-0.21, -0.0299999999999998, -0.0299999999999998, 0.16, 0.58, 
0.42, 0.62, 0.66, 0.0399999999999996, -0.96, -0.96, 0, 0, -0.04, 
-0.04, 0.71, 0.71, -0.27, -0.27, -0.54, 0.91, 1.44, 0.0599999999999996, 
0, -0.19, -0.379999999999999, -0.26, -0.0600000000000001, -0.0600000000000001, 
0.28, 0.45, 0, -0.22, -0.0499999999999998, 0.37, 0.57, 0.600000000000001, 
0, -0.95, -0.55, 0.21, 1.16, 0.04, -0.510000000000001, 0.0800000000000001, 
-0.22, 0.0999999999999996, 0.29, 0.29, -0.84, -0.84, 0.82, 0.87, 
0.0499999999999998, -0.34, -0.34, 0.0599999999999996, 0.0699999999999994, 
0.00999999999999979, 0, 0.31, 0.220000000000001, -0.0899999999999999, 
0, 0.199999999999999, 0.43, 0.23, -0.12, -0.12, -0.0199999999999996, 
-0.0199999999999996, 0, 0.52, 0.52, -0.44, -0.44, -0.0700000000000003, 
0.38, -0.29, -0.590000000000001, 0.149999999999999, 0, -0.34, 
-0.34, 0.350000000000001, 0.4, 0.0499999999999998, 0, 0.0700000000000003, 
0.0700000000000003, -0.0800000000000001, -0.0800000000000001, 
0, 0.0800000000000001, 0.66, 0.58, 0, 0.0499999999999998, 0.0499999999999998, 
-0.0300000000000002, -0.0300000000000002, -0.17, -0.42, -0.42, 
-0.37, -0.2, -0.13, 0.04, 0.17, 0.64, 0.71, 0.2, 0.13, 0.17, 
-0.51, -0.399999999999999, 0, 0, 0.26, -0.0200000000000005, 0, 
0.44, 0.75, 0.31, 0, -0.3, -0.3, 0, 0.00999999999999979, 0.00999999999999979, 
NA), .Dim = c(484L, 1L), .Dimnames = list(NULL, "ambtemp"))

dput(x.fore)
structure(list(pred = structure(c(5.77898604276542, 5.76851499635615, 
5.75806783191914, 5.74764449498526, 5.73724493120963), .Tsp = c(487, 
491, 1), class = "ts"), se = structure(c(0.32761784341869, 0.40079130692622, 
0.46226728095271, 0.516242830302498, 0.564873114585049), .Tsp = c(487, 
491, 1), class = "ts")), .Names = c("pred", "se"))

代码:

require(zoo)
require(xts)
n= 3

ambtemp <-  subset(rn25_29_o, select=c("ambtemp")) # creating subset which includes only "ambtemp" column
Median_ambtemp <- rollmedian(ambtemp,n,fill = list(NA, NULL, NA)) # smoothing the data

Dif_Median_ambtemp <- diff(Median_ambtemp, 2)

te = (x.fit = arima(Dif_Median_ambtemp, order = c(1, 0, 0)))   # fit the model and print the results
x.fore = predict(te, n.ahead=5)

1 个答案:

答案 0 :(得分:1)

这不是一个可复制的示例(我应该加载哪个包以使用rollmediann的值是多少?最好发布dput(rn25_29_o)的输出,以便我们不需要猜测数据的结构?无论如何,看看代码,我看到以下内容应该调整预测,使其与Median_ambtemp具有相同的水平:

diffinv(x.fore$pred, lag = 2, xi = tail(Dif_Median_ambtemp, 2))