在将数据集转换为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将预测覆盖到原始数据集时收到错误:
autoplot(df.ts) + autoplot(fit5)
Error: Don't know how to add o to a plot
我尝试更改开始值和结束值但我仍然得到相同的错误。我在这里错过了什么吗?我很感激,如果有人能帮助我,因为我刚刚开始使用ts格式。