0
votes

I have a data frame where one column represents my daily observed values and a date column formatted "2014-10-01" using the as.Dates function.

I'm creating an xts object doing the following:

xtsObject <- as.xts(vector$values, order.by = vector$dates)

I then pass the xtsObject into the ets forecast function and call predict on the resulting object to predict the next three time steps like so:

fit <- ets(xtsObject)
pred <- predict(fit,3)

The results look like:

       Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
366              0     0     0     0     0
367              0     0     0     0     0
368              0     0     0     0     0

(vector passed in consisted of all zeros, so the predict is working as expected)

My question is there anyway to associate these three future forecasted points with the appropriate date? My data is daily and so instead of "366", "367", "368" it would be preferable to see "10-01-2015", "10-02-2015", "10-03-2015" to know these are the dates to which these forecasted points belong to. I've tried zoo, xts, and ts and all produce similar output. Thoughts?

1

1 Answers

3
votes

Use an input zoo object and then convert the prediction to a data frame converting that data frame to a zoo object using suitably converted row names for the index:

library(zoo)

# test input
set.seed(123)
z <- zoo(rnorm(25, 1:25), as.Date("2000-01-01") + 0:24)

e <- ets(z)
p <- predict(e, 3)

DF <- as.data.frame(p)
zoo(DF, as.Date(as.numeric(rownames(DF))))

giving:

           Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
2000-01-26       25.15238 23.97099 26.33377 23.34559 26.95916
2000-01-27       26.07805 24.89666 27.25945 24.27127 27.88484
2000-01-28       27.00373 25.82234 28.18512 25.19695 28.81052