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:
data≔Importdatasets/air_passengers.csv, base=datadir, output=Matrix
data≔ 145 x 2 MatrixData Type: anythingStorage: rectangularOrder: Fortran_order
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.
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:
ts:=Time seriesMonthly Passengers144 rows of data:1949-01-01 - 1960-12-01
This data can be plotted using the TimeSeriesPlot command:
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:
This does indeed make the seasonal variation more constant. As such, you can apply a log transformation to the time series:
logts:=Time seriesLogarithm of Monthly Passengers144 rows of data:1949-01-01 - 1960-12-01
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.
model:=< an ETS(M,A,M) model >
To evaluate the fit of the model, view the OneStepForecast:
modelts:=Time seriesLogarithm of Monthly Passengers (1 step forecasts)144 rows of data:1949-01-01 - 1960-12-01
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_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
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:=Time seriesLogarithm of Monthly Passengers (residuals), ..., Logarithm of Monthly Passengers (seasonal)144 rows of data:1949-01-01 - 1960-12-01
The seasonal component is multiplicative, therefore you can compensate for it by dividing the original data by it.
trainingdata:= 144 x 1 MatrixData Type: float8Storage: rectangularOrder: Fortran_order
seasonaldata:=GetData⁡decomposition.., Logarithm of Monthly Passengers (seasonal)
seasonaldata:= 144 x 1 MatrixData Type: float8Storage: rectangularOrder: Fortran_order
nonseasonaldata ≔ TimeSeriestrainingdata /~ seasonaldata, 'header' = Logarithm of Monthly Passengers (deseasonalized), 'dates' = GetDateslogts
nonseasonaldata:=Time seriesLogarithm of Monthly Passengers (deseasonalized)144 rows of data:1949-01-01 - 1960-12-01
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.
Download Help Document
What kind of issue would you like to report? (Optional)