Forecasting Air Passenger Data - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Applications and Example Worksheets : Statistics : examples/AirPassengers

Forecasting Air Passenger Data

The following examples demonstrate techniques for analyzing time series data with the TimeSeriesAnalysis package.  

Air Passenger Data

The following example uses a data set containing the number of monthly air passengers in thousands of passengers from 1949 until 1960. The data is from Box, Jenkins, and Reinsel, as noted in the references below.

 

First step is to import the data:

dataImportdatasets/air_passengers.csv, base=datadir, output=Matrix

data 145 x 2 MatrixData Type: anythingStorage: rectangularOrder: Fortran_order

(1)

The first column lists annual dates and the second column lists number of monthly passengers for those dates. The first row is a header containing column names.

data1..5

DateMonthly Passengers1949-011121949-021181949-031321949-04129

(2)

To work with this data using the TimeSeriesAnalysis package, construct a TimeSeries object. Such an object can contain one or more data sets, measured at a common set of time points, as well as data headers and other metadata. You can construct this time series object as follows:

withTimeSeriesAnalysis:

ts:=TimeSeriesdata,'header'=1,'dates'=1,'period'=12

ts:=Time seriesMonthly Passengers144 rows of data:1949-01-01 - 1960-12-01

(3)

This data can be plotted using the TimeSeriesPlot command:

TimeSeriesPlotts

Visualizing Seasonality and Trend

From the previous plot, it can be observed that the time series seems to have a strong seasonal component that may be either linear or quadratic. Moreover, the magnitude of the seasonal variation increases as the number of passenger arrivals increases. To see if applying a log transformation to the data in order to make the magnitude of the seasonal variation more constant, you can first try to plot the time series with a log scale:

TimeSeriesPlotts,axis2=mode=log

This does indeed make the seasonal variation more constant. As such, you can apply a log transformation to the time series:

logtsApplyLogTransform, ts

logts:=Time seriesLogarithm of Monthly Passengers144 rows of data:1949-01-01 - 1960-12-01

(4)

TimeSeriesPlotlogts

 

You can also look for trends in the data using the SeasonalSubseriesPlot command. The following plot shows that the year-to-year increase for each month is constant for the number of passenger arrivals.

SeasonalSubseriesPlotlogts,seasonnames=January,February,March,April,May,June,July,August,September,October,November,December,size=800,400,title=Yearly trend by month

Modeling Future Passenger Arrivals

To forecast future passenger arrivals, first find a suitable model to match the actual data. Maple can select a suitable model from a family of 30 related models and adjust it to this time series.

modelExponentialSmoothingModellogts

model:=< an ETS(M,A,M) model >

(5)

To evaluate the fit of the model, view the OneStepForecast:

modeltsOneStepForecastsmodel&comma;logts

modelts:=Time seriesLogarithm of Monthly Passengers (1 step forecasts)144 rows of data:1949-01-01 - 1960-12-01

(6)

TimeSeriesPlotmodelts&comma;color&equals;CornflowerBlue&comma;thickness&equals;2&comma;logts&comma;color&equals;Niagara Burgundy&comma;thickness&equals;2

 

From this plot, you can see that there is reasonable agreement between the forecast and the data. Using the model data, you can predict two years of future data using the forecast command, including a 95% confidence interval:

forecast_tsForecastmodel&comma;logts&comma;24&comma;output&equals;confidenceintervals95

forecast_ts:=Time seriesLogarithm of Monthly Passengers (forecast - 2 percentile), Logarithm of Monthly Passengers (forecast - 50 percentile), Logarithm of Monthly Passengers (forecast - 98 percentile)24 rows of data:1960-12-31 - 1962-12-01

(7)

TimeSeriesPlotlogts&comma;forecast_ts&comma;linestyle&equals;dash&comma;thickness&equals;1

Further Explorations

The chosen model can be used to decompose the data set into several components. The number of components depends on the model. This is done using the Decomposition command. For an exponential smoothing model, there are always level and residual components. There can also be trend and seasonal components depending on whether or not the model has those properties. This can, for example, be used to correct for seasonal influences or smooth data.

decomposition:=Decompositionmodel&comma;logts

decomposition:=Time seriesLogarithm of Monthly Passengers (residuals), ..., Logarithm of Monthly Passengers (seasonal)144 rows of data:1949-01-01 - 1960-12-01

(8)

TimeSeriesPlotlogts&comma;decomposition&comma;split&equals;separate

 

The seasonal component is multiplicative, therefore you can compensate for it by dividing the original data by it.

trainingdata:=GetDatalogts

trainingdata:= 144 x 1 MatrixData Type: float8Storage: rectangularOrder: Fortran_order

(9)

seasonaldata:=GetDatadecomposition..&comma; Logarithm of Monthly Passengers (seasonal)

seasonaldata:= 144 x 1 MatrixData Type: float8Storage: rectangularOrder: Fortran_order

(10)

nonseasonaldata  TimeSeriestrainingdata /~ seasonaldata&comma; &apos;header&apos; &equals; Logarithm of Monthly Passengers (deseasonalized)&comma; &apos;dates&apos; &equals; GetDateslogts

nonseasonaldata:=Time seriesLogarithm of Monthly Passengers (deseasonalized)144 rows of data:1949-01-01 - 1960-12-01

(11)

TimeSeriesPlotnonseasonaldata

References

  

Box, G.E.P.; Jenkins, G.M.; and Reinsel, G.C. Time Series Analysis, Forecasting and Control. Third Edition. Holden-Day. Series G, 1976.

  

Hyndman, R.J. and Athanasopoulos, G. Forecasting: principles and practice. 2013. http://otexts.org/fpp/. Accessed on 2013-10-09.

  

Hyndman, R.J.; Koehler, A.B.; Ord, J.K.; and Snyder, R.D. Forecasting with Exponential Smoothing: The State Space Approach. Springer Series in Statistics. Springer-Verlag Berlin Heidelberg, 2008.