当我尝试使用RUCM包中的预测函数来获取模型的预测未来值时,我收到错误“模型不是类'SSModel'的正确对象'。
我的代码如下:
batData <- read.csv("C:/Users/adsofihadsf/Desktop/Test.csv")
timeSeries <- ts(batData$Accidents, start=c(0, 1), end=c(12, 4), frequency=4)
model <- ucm(timeSeries~0, data = timeSeries, slope = TRUE)
predict(model$model, n.ahead=4)
一切都很好,直到预测功能。而且,如果我继续检查模型变量的内容,它看起来就像我期望的那样。我甚至试图在默认的R Nile River数据集上重新运行它。它在那里工作得很好......
modelNile <- ucm(Nile~0, data = Nile, slope = TRUE)
predict(modelNile$model, n.ahead = 12)
世界上到底发生了什么?
数据(Test.csv):
Accidents,Fuel
192,32.592
238,37.25
232,40.032
246,35.852
185,38.226
274,38.711
266,43.139
196,40.434
170,35.898
234,37.111
272,38.944
234,37.717
210,37.861
280,42.524
246,43.965
248,41.976
269,42.918
326,49.789
342,48.454
257,45.056
280,49.385
290,42.524
356,51.224
295,48.562
279,48.167
330,51.362
354,54.646
331,53.398
291,50.584
377,51.32
327,50.81
301,46.272
269,48.664
314,48.122
318,47.483
288,44.732
242,46.143
268,44.129
327,46.258
253,48.23
215,46.459
263,50.686
319,49.681
263,51.029
206,47.236
286,51.717
323,51.824
306,49.38
230,47.961
304,46.039
311,55.683
292,52.263
答案 0 :(得分:0)
显然,问题是将数据转换为时间序列......用以下固定的东西很容易地替换代码......
batData <- read.csv("C:/Users/aosdhfoaidshf/Desktop/Test.csv")
model <- ucm(Accidents~0, data = batData, slope = TRUE)
plot(batData$Accidents)
lines(predict(model), col="blue")
不幸的是,RUCM documentation对此非常不清楚。它说UCM功能“分解时间序列”,该例子使用Nile数据(这是一个时间序列)。对我来说,为什么上面的代码适用于尼罗河时间序列仍然是一个谜,但不是我的自定义代码...但是无论如何。它现在有效。