Difference - Maple Help

Online Help

All Products    Maple    MapleSim

Statistics

 Difference
 compute lagged differences between elements in a data set

 Calling Sequence Difference( X ) Difference( X, options )

Parameters

 X - data set, DataSeries, DataFrame, or TimeSeries; numeric list of values options - (optional) equation(s) of the form option=value where option can be times or lag

Options

 • times : posint; positive integer value indicating the number of times (order) to perform lagged differences. The default is 1.
 • lag : posint; positive integer value indicating the lag (staggering) of the differenced elements. The default is 1.
 Description The Difference command is used to compute lagged differences between elements in a data set. If X is a vector of length n and times = 1, then the computed result is equal to the successive differences X[(1+lag)..n] - X[1..(n-lag)]. If X is a multi-column data set, then the differencing algorithm is run on each column of data individually.

Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$

Define some data:

 > $x≔⟨\mathrm{seq}\left({i}^{2},i=1..10\right)⟩$
 $\left[\begin{array}{r}1\\ 4\\ 9\\ 16\\ 25\\ 36\\ 49\\ 64\\ 81\\ 100\end{array}\right]$ (1)

To compute the differences between terms in the data, the Difference command is used.

 > $\mathrm{Difference}\left(x\right)$
 $\left[\begin{array}{r}3\\ 5\\ 7\\ 9\\ 11\\ 13\\ 15\\ 17\\ 19\end{array}\right]$ (2)

The times option makes it possible to apply the difference multiple times.

 > $\mathrm{Difference}\left(x,\mathrm{times}=2\right)$
 $\left[\begin{array}{r}2\\ 2\\ 2\\ 2\\ 2\\ 2\\ 2\\ 2\end{array}\right]$ (3)

Note that this is equivalent to running:

 > $\mathrm{Difference}\left(\mathrm{Difference}\left(x\right)\right)$
 $\left[\begin{array}{r}2\\ 2\\ 2\\ 2\\ 2\\ 2\\ 2\\ 2\end{array}\right]$ (4)

The lag option staggers the differencing. Using a lag of 2 subtracts the first value from the third value, the second from the fourth, and so on:

 > $\mathrm{Difference}\left(x,\mathrm{lag}=2\right)$
 $\left[\begin{array}{r}8\\ 12\\ 16\\ 20\\ 24\\ 28\\ 32\\ 36\end{array}\right]$ (5)

The Difference command can also be applied directly to TimeSeries data.

 > $\mathrm{ts}≔\mathrm{TimeSeriesAnalysis}:-\mathrm{TimeSeries}\left(\left[1,4,9,16\right]\right)$
 ${\mathrm{ts}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set}}\\ {\mathrm{4 rows of data:}}\\ {\mathrm{2017 - 2020}}\end{array}\right]$ (6)
 > $\mathrm{Difference}\left(\mathrm{ts}\right)$
 $\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{data set \left(differenced\right)}}\\ {\mathrm{3 rows of data:}}\\ {\mathrm{2018 - 2020}}\end{array}\right]$ (7)
 > $\mathrm{GetData}\left(%\right)$
 $\left[\begin{array}{c}3.0\\ 5.0\\ 7.0\end{array}\right]$ (8)
 > 

Compatibility

 • The Statistics[Difference] command was introduced in Maple 2019.
 • For more information on Maple 2019 changes, see Updates in Maple 2019.

 See Also