简体   繁体   中英

Time series prediction with and without NAs (ARIMA and Forecast package) in R

This is my first question on stack overflow.

Situation: I have 2 time series. Both series have the same values but the second series has 5 NAs at the start. Hence, first series has 105 observations, where 2nd series has 110 observations. I have fitted an ARIMA(0,1,0) using the Arima function to both series separately. And then I used the forecast package to predict 10 steps to the future.

Issue: Even though the ARIMA coefficient for both series are the same, the projections (10 steps) appear to be different. I am uncertain why this is the case. Has anyone come across this before? Any guidance is highly appreciated.

Tried: I tried setting seed, creating index manually, and using auto.ARIMA for the model fitting. However, none of the steps has helped me to reconcile the difference.

I have added a picture to show you what I see. Please note I have hidden the mid part of the series so that you can see the start and the end of the series. The yellow highlighted cells are the projection outputs from the 'Forecast' package. I have manually added the index to be years after extracting the results from R.

Time series projected and base in excel

Rates <- read.csv("Rates_for_ARIMA.csv")

set.seed(123)

#ARIMA with NA
Simple_Arima <- Arima(
            ts(Rates$Rates1),
            order = c(0,1,0),
            include.drift = TRUE)

fcasted_Arima <- forecast(Simple_Arima, h = 10)
fcasted_Arima$mean

#ARIMA Without NA

Rates2 <- as.data.frame(Rates$Rates2)
##Remove the final spaces from the CSV
Rates2 <- Rates2[-c(106,107,108,109,110),] 

Simple_Arima2 <- Arima(
  ts(Rates2),
  order = c(0,1,0),
  include.drift = TRUE)

fcasted_Arima2 <- forecast(Simple_Arima2, h = 10)
fcasted_Arima2$mean

The link to data is here, CSV format

Could you share your data and code such that others can see if there is any issue with it?

I tried to come up with an example and got the same results for both series, one that includes NAs and one that doesn't.

library(forecast)
library(xts)

set.seed(123)
ts1 <- arima.sim(model = list(0, 1, 0), n = 105)
ts2 <- ts(c(rep(NA, 5), ts1), start = 1)

fit1 <- forecast::Arima(ts1, order = c(0, 1, 0))
fit2 <- forecast::Arima(ts2, order = c(0, 1, 0))

pred1 <- forecast::forecast(fit1, 10)
pred2 <- forecast::forecast(fit2, 10)

forecast::autoplot(pred1)
forecast::autoplot(pred2)

> all.equal(as.numeric(pred1$mean), as.numeric(pred2$mean))
[1] TRUE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM