Search code examples
rforecastets

How to forecast continuous in R


I'm novice in R and im doing a forecast for my dataset, as you can see in the diagram, the data before 2019,04 is training data, the part in blue (start from 2019,04- 2019,12) is my forecast and the red line is the test data(2019,04- 2019,12), the time interval is identical, but in the diagram it isn't continuous, how can I fix it?

library(forecast)

fit_ets %>% forecast(h=9) %>%
autoplot()+
autolayer(testing)

enter image description here


Solution

  • if by continuous you mean that the black line is not "connected" to the red nor the blue: each line has a first and last observation which are connected via lines (and have possibly more observations).

    Your first value to predict (or test) is, chronologically speaking, after the training data, thus the black line will not reach the blue and red. Also the blue and red line can not reach back to connect as the last observation from training data is not included in theire data.

    After forecasting you could include the last observation from the training data in test and prediction set. This will lead to a "continuous" line when plotting.