I'm trying to create a Holt-Winters forecast from a weekly time series, then plot the original series and forecast using dygraphs. I have 144 weeks of friday week-ending data. For my purpose, I'm ignoring that some years have 53 weeks. The structure of the data can be simulated by:
## create data similar to what I have
week_date <- seq.Date(from = as.Date("2012/05/11"),
by = "week",
length.out = 144)
set.seed(1)
var1 <- diffinv(rnorm(143))
df <- data.frame(cbind(week_date, var1))
## convert to ts object then
## create Holt Winters forecast
dfts <- ts(df[,2],freq=52, start=c(2012,19))
hw <- HoltWinters(dfts)
p <- predict(hw, 4)
all <- cbind(dfts, p)
## create plots
dygraph(all, "time series dygraph") %>%
dySeries("var1", label = "Actual") %>%
dySeries(c("p.lwr", "p.fit", "p.upr"), label = "Predicted")
This produces the following error:
Error in as.xts.ts(data) : could not convert index to appropriate type
I tried the solution proposed here, but am getting the same error:
> all <- cbind(dfts = as.xts(dfts), p = as.xts(p))
Error in as.xts.ts(dfts) : could not convert index to appropriate type