Categories
2. You Should Know about Time Series Forecasting in R

Creating of a Box Plot by Cycle

boxplot(AirPassengers~cycle(AirPassengers, xlab=”Date”, ylab = “Passenger Numbers (1000’s)”, main = “Monthly air passengers boxplot from 1949-1960”))

Time_Series-11

From the above plot, you can see that the number of ticket sales goes higher in June, July, and August as compared to the other months of the years. 

  • Build the ARIMA Model Using auto.arima() Function

mymodel <- auto.arima(AirPassengers)

mymodel

Time_Series-12
  • Plot the Residuals

plot.ts(mymodel$residuals)

Time_Series-13
  • Forecast the Values for the Next 10 Years

myforecast <- forecast(mymodel, level=c(95), h=10*12)

plot(myforecast)

Time_Series-14
  • Validate the Model by Selecting Lag Values

Box.test(mymodel$resid, lag=5, type=”Ljung-Box”)

Time_Series-15

Box.test(mymodel$resid, lag=10, type=”Ljung-Box”)

time series16

Box.test(mymodel$resid, lag=15, type=”Ljung-Box”)

Time_Series-17

Looking at the lower p values, we can say that our model is relatively accurate, and we can conclude that from the ARIMA model, that the parameters (2, 1, 1) adequately fit the data. 

Leave a Reply

Your email address will not be published. Required fields are marked *