Home > Blockchain >  Forecasting time series data (creating predictions)
Forecasting time series data (creating predictions)

Time:08-04

I have my data as a ts which i am trying to forecast the values from 2014 Qtr2 to 2015 Qtr 3. I have used the following code but it seems to skip the remaining 3 quarters for 2014 and only predict for 2015. Does anyone know how i can get the 2014 values included aswell?

x
          Qtr1      Qtr2      Qtr3      Qtr4
2004        NA 15.347126 23.749583 17.652204
2005 13.950342 18.667970 21.739828 22.497550
2006 17.116492 17.714298 20.501897 20.841587
2007 18.918347 15.460020 17.872199 20.017007
2008 18.508666 15.530639 16.066960 20.216581
2009 16.255357 14.856708 15.282690 12.160845
2010  8.889602 16.180422 19.743183 15.056486
2011 15.130970 15.966518 17.790699 18.351916
2012 15.793286 11.903337 16.378045 16.457062
2013 11.867353 17.076883 17.606403 18.814323
2014 15.119643        NA        NA        NA

model

mod = auto.arima(x, max.p = 4, max.q = 4, max.d = 0, seasonal = FALSE)

forecasting

forecast1 = predict(mod, n.ahead = 3)
forecast1$pred

output given

       Qtr1     Qtr2     Qtr3
2015 16.92403 16.93467 16.93788

output required (obviously with values replacing the ?)

       Qtr1     Qtr2     Qtr3   Qtr4
2014             ?        ?      ?
2015 16.92403 16.93467 16.93788

CodePudding user response:

It is good to remove NA now, otherwise predict() thinks the series ends on 2014.Qtr4, not 2014.Qtr1:

xx <- na.omit(x)
mod = auto.arima(xx, max.p = 4, max.q = 4, max.d = 0, seasonal = FALSE)
predict(mod, n.ahead = 3)
#$pred
#         Qtr2     Qtr3     Qtr4
#2014 13.70785 17.79853 16.86842
#
#$se
#         Qtr2     Qtr3     Qtr4
#2014 2.614327 3.092998 3.156169
  • Related