Reputation: 6149
Simple question -- I want to extract the fitted values and mean forecast of an ARIMA as one single time series, using R. Right now, I use this slow and cumbersome code:
x<-auto.arima(y)
z<-forecast(x, 365)
fitted<-z$fitted
mean<-z$mean
merged<-merge.zoo(fitted, mean)
merged$fitted[is.na(merged$fitted)]<-0
merged$mean[is.na(merged$mean)]<-0
finalforecast<-merged$fitted+ merged$mean
There must be an esier way to do this, but looking at the documentation, I'm drawing a blank. I really want to avoid the hassle of merging the time series, then dropping in zeroes (to fill the NAs), and then doing the addition. I know I can create my own function, but I'd be surprised if there isn't something simple that's pre-baked.
Thoughts?
Upvotes: 0
Views: 2778
Reputation: 3210
Why not just c(z$fitted, z$mean)
?
EDIT:
If you need a ts
object: ts(c(z$fitted, z$mean), start=start(y), frequency=frequency(y))
Upvotes: 3