|
Calling Sequence
|
|
Apply(Difference, timeseries)
Apply(Difference(times = n, lag = k), timeseries)
Unapply(Difference, forecast)
Unapply(Difference(times = n, lag = k), forecast)
Unapply(Difference(times = n, lag = k), forecast, origin = o)
|
|
Parameters
|
|
timeseries
|
-
|
TimeSeries data set
|
n
|
-
|
positive integer (optional)
|
k
|
-
|
positive integer (optional)
|
forecast
|
-
|
TimeSeries data set, typically obtained from a forecasting method
|
o
|
-
|
specification of origin ; list of Matrices
|
|
|
|
|
Description
|
|
•
|
The differencing transformation takes a time series and returns the time series .
|
•
|
Apply this transformation to a time series using the Apply command. Translate differenced information such as forecasts back to the original domain by using the Unapply command.
|
•
|
By using the option, one can difference a time series with a given lag. In particular, the transformation transforms the time series into . The default lag is 1.
|
•
|
If there are missing data points (represented in Maple by the value in the time series), the differencing transformation skips over them while leaving the undefined value in place. For example, if is undefined, then the result of differencing with is
|
This is done so that Unapply can recover the data.
•
|
By using the option, one can specify the transformation that consists of differencing multiple times. The default is . Specifying , for example, describes the transformation that takes the time series to .
|
•
|
Every time differencing is applied, the resulting time series has data points fewer than the input. This is reflected in the timestamps; the first timestamp is omitted from the resulting time series. In other words, the timestamp for the difference is taken to be the time at which occurred, because it is only at this time that both and are available and the first difference can be computed.
|
•
|
For the Unapply call, to transform back into the original , Maple needs to know the value , which will be referred to as the origin. If the forecast is created using TimeSeriesAnalysis commands, then Unapply can generally find the time series object from which the original differences were taken, and use this object to infer the origin. Otherwise, or to override this choice, the origin can be specified explicitly using the option.
|
In the example above, only a single number was needed. However, if contains data sets, then a Vector of origins is needed - one for every data set. Moreover, if , then each data set needs independent origins; all of these are arranged in a x_m_ Matrix. Finally, with , we need such a Matrix for every differencing operation that is undone.
The most explicit way to specify the origin argument is therefore as a list of Matrices, each of size x_m_. However, several shortcuts are available:
–
|
A Matrix can be specified as a list or Vector of the elements needed.
|
–
|
A Matrix can be specified as the list or Vector of the elements of its first row; this row will be repeated times.
|
–
|
A Matrix can be specified as a single number, which the Matrix will be filled with.
|
–
|
Instead of a list of Matrices, you can specify a single Matrix, each row of which will be expanded into a by repeating it times.
|
–
|
Finally, if you specify a single number, it will be used to fill all of the
|
|
|
Examples
|
|
>
|
|
>
|
|
| (1) |
>
|
|
| (2) |
Here are the differences in sales from week to week.
>
|
|
| (4) |
Reconstructing the original data (except for the first row):
>
|
|
| (6) |
The original data, differenced twice:
>
|
|
| (8) |
>
|
|
You can do this in one step, too. The header gets a bit nicer name in this case:
>
|
|
| (10) |
>
|
|
Unapplying differencing twice leads to the original data (minus the first two rows).
>
|
|
| (12) |
>
|
|
| (14) |
You can also perform two operations of unapplying differencing once, to either or .
>
|
|
| (16) |
>
|
|
>
|
|
| (18) |
>
|
|
| (20) |
>
|
|
>
|
|
| (22) |
If you expect a biweekly pattern, you can difference with lag = 2.
>
|
|
| (24) |
>
|
|
If one of the data points were missing, you can still do the transformation and back-transformation.
>
|
|
| (26) |
>
|
|
| (27) |
>
|
|
| (28) |
>
|
|
| (29) |
>
|
|
| (30) |
|
Specifying the option
|
|
•
|
Consider the following time series.
|
>
|
|
| (31) |
| (32) |
•
|
If you try to unapply a differencing operation, Maple complains that it cannot find the origin.
|
>
|
|
•
|
With and (the default), you need to specify a list of one x_2_ Matrix.
|
>
|
|
| (33) |
| (34) |
•
|
This can also be specified as just the list .
|
>
|
|
| (35) |
| (36) |
•
|
If you set , you need to specify values for three previous data points for each data set. You can give a list with a single Matrix - or just specify the Matrix directly.
|
>
|
|
| (37) |
| (38) |
•
|
If you set and , then you need to specify all these values for both times that you unapply differencing. The two matrices need to be specified in a list, in the order in which they will be used.
|
>
|
|
| (39) |
| (40) |
|
|
|
Compatibility
|
|
•
|
The TimeSeriesAnalysis[Difference] command was introduced in Maple 18.
|
|
|
|