Manu Ruiz Ruiz
Manu Ruiz Ruiz

Reputation: 393

Adding two forecast objects in R

I have two forecast objects, one obtained with ARIMA, where I forecast a deseasoned time series, and the other one that involves the seasonal component of the previous ts, forecasted with the seasonal naive method, so it repeats the last years. I'd like to combine those forecast in one object, by adding its values. How can I do it?

Here's the code

ts.comp <- stl(ts,  s.window="periodic")
deseasonal_ts <- seasadj(ts.comp)
fit <- auto.arima(deseasonal_ts, seasonal=FALSE)
prediction <- forecast(fit, h=30)

seasonal_ts <- ts.comp$time.series[,1]
seasonal_ts_prediction<- snaive(seasonal_ts, 30)

I'd like to combine prediction and seasonal_ts_prediction. Is this possible?

Upvotes: 0

Views: 234

Answers (1)

Lstat
Lstat

Reputation: 1460

This can be done in the following way:

predComb <- prediction$mean + seasonal_ts_prediction$mean

You can see the outcome:

foo <- ts.union(nottem, predComb) # for the nottem time-series 
plot(foo)

enter image description here

Upvotes: 2

Related Questions