Time Series Analysis

The TimeSeriesAnalysis package is new to Maple 18 and deals with any data that varies with time. In particular, any data where the time intervals between data points are regular, such as with macroeconomical data and in many other fields like statistics, signal processing, econometrics, and mathematical finance. The TimeSeriesAnalysis package has many tools working with data including tools for analyzing and modeling, finding patterns and forecasting, and visualizing time series data.

>

Forecasting

Seasonal Analysis

Using the Time Series Analysis Package

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, noted in the references below.

>

>

The data has one column of dates (year) and one column of data (monthly passengers). The first row is a header.

>

To work with this data, 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:

>

The options above indicate that the first row and column contain a header and the dates, respectively, and that you expect any seasonal characteristics to occur with period 12.

To inspect the data, you can use the GetData, GetDates, and GetHeaders commands.

>

>

>

Alternatively, you can plot the data using the TimeSeriesPlot command.

>

We can also look for seasonal trends in our data using the SeasonalSubseriesPlot command. The following plot shows the number of passengers on a monthly basis.

>

You can now have Maple select a suitable model from a family of 30 related models, and adjust it to this time series. In fact, you will adjust it to the first 10 years of data; this can be done by specifying the time range as an index.

>

>

The family of models used is an exponential smoothing model.

>

You can observe that the best model in this case has multiplicative errors, a multiplicative trend, and multiplicative seasonal information. You can get the details on this exponential smoothing model using the GetParameters command.

>

Use the model to predict two years of future data using the forecast command: the actual data for this time range is in tsverify;.

>

The forecast is itself a time series object that can be inspected using GetData, GetHeaders, and other commands.

>

>

There is reasonable agreement between the forecast and the verification data. You get a better handle on this if you include confidence intervals for all data points. You can then see how often the true data falls within the boundaries of the confidence intervals.

>

>

Use the model 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 may also be trend and seasonal components depending on whether or not the model has those properties. This can be used to, for example, correct for seasonal influences or smooth data.

>

>

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

>

>

>

>

Working with Time Series Data

There are several commands that can be used to modify existing time series objects. Using the data from above, you can use the Join command to merge the forecast with the training data set.

>

>

Another command, Difference, applies a differencing transformation in a flexible way. The LogTransform command applies a logarithm transformation, and BoxCoxTransform generalizes that to a general Box-Cox transformation.

>

>

>

>

More Details on Choosing Exponential Smoothing Models

You can manually step through the process of finding a suitable model for the data set using the Specialize, Initialize, and Optimize commands. The ExponentialSmoothingModel command generates an exponential smoothing model object; it represents a wide range of models. In this case, you can see that the data has a strong seasonal component, so you might be able to guess that you can discard the models that do not take the seasonal component into account.

>

You can now specialize this to all individual model formulations represented by the general model. That is, where the seasonal component is additive or multiplicative. Some models are excluded by default because they are subject to numerical difficulties: the forecasts have infinite variance. (They can be included by overriding an option to Specialize.)

>

Each individual model now has a slightly different set of model equations. They all still have a number of parameters and initial values for the model's state variables and need to be optimized for the best fit. This optimization process consists of a number of iterations. In each iteration, Maple picks a new set of values for the parameters and initial state values, then runs the simulation using the model, and finally, computes the deviations from the actual observed data. The first set of values (which initializes the optimization process) is computed directly from the actual data, by the Initialize command.

>

Here is an example of these initialization values:

>

You can now perform the optimization.

>

The optimization process sets all parameters and initial state values to the optimal values found. The Optimize command returns a measure for how close the fit between the simulation run and the actual data is. However, these models all have different numbers of parameters. If a similar fit is achieved with a model that has fewer parameters, then the principle of parsimony says you should prefer the latter model. This is quantified in a so-called information criterion: a function that takes both the closeness of the fit and the number of parameters into account. The TimeSeriesAnalysis package has three information criteria built in: two versions of Akaike's Information Criterion (AICc, which includes a correction for small data sizes, and AIC, which does not), and the Bayesian Information Criterion (BIC). Let us compare the BIC for all these models.

>

>

From the results, the , ,, ), and (models give the best results in terms of the Bayesian information criterion.

References

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