在 R 中绘制初始数据和预测数据(aima 模型)

Plot initial data and predicted data (aima model) in R

我有一个数据框,例如 df[[i]] 对象:

c(0.115357, 0.081623, 0.064095, 0.037976, 0.034594, 0.072012, 0.062988,
0.029926,0.016034, 0.068849, 0.045474, 0.014287, 0.042347, 
0.012183, 0.007037, 0.010355, 0.035283, 0.006473, 0.003692, 0.002738, 
0.003707, 0.002289, 0.001643, 0.001023, 0.000878, 6e-04, 0.000851, 
0.000645, 0.000968, 0.000856, 0.000637, 0.00052, 0.000611, 0.000397, 
0.000193, 1e-04, 7.5e-05, 7.2e-05, 7.4e-05, 4e-05, 4e-05)

我尝试绘制相同的数据:

对于我的数据框,火车数据是:

dfL_F[[28]][1:25]

并预测数据:

forecast1 <- predict(arimaModel_1, 16)

有我的代码:

arimaModel_1 <- arima(dfL_F[[28]][1:25], order = c(1,1,2), method = "CSS")
forecast1 <- predict(arimaModel_1, 16)
ts.plot(as.ts(dfL_F[[28]][1:25]),forecast1)

我得到错误:

ts.plot(as.ts(dfL_F[[28]][1:25]),forecast1)
Error in .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union = TRUE) : 
  non-time series not of the correct length

如何为我的案例绘制不同阶数的 ARIMA 和初始数据?

对不起,这个post并不能解决我的问题Predict and plot after fitting arima() model in R

forecast1 是两个元素的 list

> str(forecast1)
List of 2
 $ pred: Time-Series [1:16] from 26 to 41: -2.62e-05 1.53e-04 2.36e-04 2.75e-04 2.93e-04 ...
 $ se  : Time-Series [1:16] from 26 to 41: 0.0167 0.0168 0.0171 0.018 0.0191 ...

它returns一个list因为用法predict.Arima

predict(object, n.ahead = 1, newxreg = NULL, se.fit = TRUE, ...)

哪里

se.fit - Logical: should standard errors of prediction be returned?

因此,默认情况下它 returns 预测的标准误差,如果我们使用完整的 list,它 returns 误差

ts.plot(as.ts(dfL_F[[28]][1:25]), forecast1)
Error in .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union = TRUE) : 
  non-time series not of the correct length

我们需要提取 pred

ts.plot(as.ts(dfL_F[[28]][1:25]), forecast1$pred)

-输出