0

将我的数据集转换为 ts 格式后,我收到“错误:不知道如何将 o 添加到绘图中”。我正在做一个预测项目,我有这个从 xts 转换为 ts 的数据集:

library(tidyverse)
library(TTR)
library(forecast)

            [,1]
1998-12-31 0.025
1999-12-31 0.038
2000-12-31 0.086
2001-12-31 0.142
2002-12-31 0.190
2003-12-31 0.273
2004-12-31 0.394
2005-12-31 0.406
2006-12-31 0.483
2007-12-31 0.612
2008-12-31 0.746
2009-12-31 0.823
2010-12-31 0.930
2011-12-31 0.987
2012-12-31 1.064
2013-12-31 1.100
2014-12-31 1.160
2015-12-31 1.152
2016-12-31 1.204

#convert to ts
df.ts <- ts(df.xts, start = c(1998,1), end = c(2016,1), frequency = 1)

#select training period
train <- window(df.ts, end = c(2013, 1))

#simple naive forecasting model
fit5 <- train %>%
  snaive(h = h)

一旦我尝试通过自动绘图将我的预测覆盖到原始数据集,我就会收到错误消息:

autoplot(df.ts) + autoplot(fit5)
Error: Don't know how to add o to a plot

我尝试更改开始值和结束值,但仍然出现相同的错误。我在这里错过了什么吗?如果有人可以帮助我,我将不胜感激,因为我刚刚开始使用 ts 格式。

4

0 回答 0