Is there an easier way to extract combined fitted values and forecast values of an ARIMA in R?

StackOverflow https://stackoverflow.com/questions/16548408

  •  29-05-2022
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top