I am new to R and have found this site extremely helpful, so this covers the second half of my question (one issue per post). Thank you for your assistance ahead of time.
Background: I was plotting historical data with multiple forecasts overlaid for visual accuracy checks. This worked great when displayed on an x axis of 'observations'. However, the data is more understandable when plotted with dates on the x axis, so I made it a time series using ts() and it plotted the time series data as expected. However, (A) it did not plot the forecast data on the time scale because they are not a time series; and (B) I was unsure how to force the x axis to plus 1 year to permit the forecast to display.
Question: (A) How do I restore the original time stamps to the forecast data? I know that I could manually recreate the time series, but this would be required in every iteration of the forecast. I have considered using forecast() instead of predict(), but the additional forecast iterations still have the same issue of not being a time series. Is there a simple way to restore the original time stamp to the forecast data?
require(forecast) [EDITED for clarity]
data <- rep(cos(1:52*(3.1416/26)),5)*100+1000
arima.ts <- ts(data,start=c(2009,1),frequency=52) #not plotted as time series
# Create the current fit on data and predict one year out
plot(arima.ts, type="l", xlab="weeks", ylab="counts",
main="Overlay forecasts & actuals",
sub="green=FIT(1-105,by 16) wks back & PREDICT(26) wks, blue=52 wks")
############## This plotted correctly as "Arima(data),..."
arima.fit <- auto.arima(tail(arima.ts,156))
arima.pred <- predict(arima.fit, n.ahead=52)
lines(arima.pred$pred, col="blue")
lines(arima.pred$pred+2*arima.pred$se, col="red")
lines(arima.pred$pred-2*arima.pred$se, col="red")
# Loop back and perform comparison plotting of forecast to actuals
for (j in seq(1,105,by=16)) {
result <- tryCatch({
############## This plotted correctly as "Arima(head(data,-j),..."
arima1.fit <- auto.arima(head(tail(arima.ts,-j),156))
arima1.pred <- predict(arima1.fit, n.ahead=52)
lines(arima1.pred$pred, col="green", lty=(numtests %% 6) + 1 )
}, error = function(e) {return(e$message)}) ## Trap errors
}