TimeSeriesAnalysis - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Statistics and Data Analysis : Time Series Analysis Package : TimeSeriesAnalysis/Difference

TimeSeriesAnalysis

  

Difference

  

differencing transformation

 

Calling Sequence

Parameters

Description

Examples

Compatibility

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 T1,T2,T3,... and returns the time series T2T1,T3T2,....

• 

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 lag option, one can difference a time series with a given lag. In particular, the transformation Differencelag=2 transforms the time series T1,T2,T3,... into T3T1,T4T2,T5T2,.... The default lag is 1.

• 

If there are missing data points (represented in Maple by the value undefined in the time series), the differencing transformation skips over them while leaving the undefined value in place. For example, if T4 is undefined, then the result of differencing with lag=2 is

T3T1,undefined,T5T3,T6T2,T7T5,T8T6,... .

This is done so that Unapply can recover the data.

• 

By using the times option, one can specify the transformation that consists of differencing multiple times. The default is times=1. Specifying times=2, for example, describes the transformation that takes the time series T1,T2,T3,... to T1+T32T2,T2+T42T3,....

• 

Every time differencing is applied, the resulting time series has k 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 T2T1 is taken to be the time at which T2 occurred, because it is only at this time that both T1 and T2 are available and the first difference can be computed.

• 

For the Unapply call, to transform T2T1,T3T2,... back into the original T1,T2,T3,..., Maple needs to know the value T1, 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 origin=o option.

In the example above, only a single number was needed. However, if forecast contains m data sets, then a Vector of m origins is needed - one for every data set. Moreover, if lag=k, then each data set needs k independent origins; all of these are arranged in a kx_m_ Matrix. Finally, with times=n, 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 n Matrices, each of size kx_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 k times.

– 

A Matrix can be specified as a single number, which the kxm Matrix will be filled with.

– 

Instead of a list of Matrices, you can specify a single nxm Matrix, each row of which will be expanded into a kxm by repeating it k times.

– 

Finally, if you specify a single number, it will be used to fill all n of the kxm 

Examples

withTimeSeriesAnalysis:

sales_numbers150,147,114,113,91,164,56,39,32,86

sales_numbers:=1501471141139116456393286

(1)

salesTimeSeriessales_numbers,startdate=2010-01-01,frequency=weekly,header=Weekly Sales

sales:=Time seriesWeekly Sales10 rows of data:2010-01-01 - 2010-03-05

(2)

GetDatasales..5

150.147.114.113.91.

(3)

Here are the differences in sales from week to week.

differencedApplyDifference,sales

differenced:=Time seriesWeekly Sales (differenced)9 rows of data:2010-01-08 - 2010-03-05

(4)

GetDatadifferenced..4

3.33.1.22.

(5)

Reconstructing the original data (except for the first row):

originalUnapplyDifference,differenced

original:=Time seriesWeekly Sales9 rows of data:2010-01-08 - 2010-03-05

(6)

GetDataoriginal..4

147.114.113.91.

(7)

The original data, differenced twice:

differenced_twiceApplyDifference,differenced

differenced_twice:=Time seriesWeekly Sales (differenced) (differenced)8 rows of data:2010-01-15 - 2010-03-05

(8)

GetDatadifferenced_twice..3

30.32.21.

(9)

You can do this in one step, too. The header gets a bit nicer name in this case:

differenced_twice_2ApplyDifference'times'=2,sales

differenced_twice_2:=Time seriesWeekly Sales (differenced twice)8 rows of data:2010-01-15 - 2010-03-05

(10)

GetDatadifferenced_twice_2..3

30.32.21.

(11)

Unapplying differencing twice leads to the original data (minus the first two rows).

original_2UnapplyDifference'times'=2,differenced_twice

original_2:=Time seriesWeekly Sales8 rows of data:2010-01-15 - 2010-03-05

(12)

GetDataoriginal_2..3

114.113.91.

(13)

original_3UnapplyDifference'times'=2,differenced_twice_2

original_3:=Time seriesWeekly Sales8 rows of data:2010-01-15 - 2010-03-05

(14)

GetDataoriginal_3..3

114.113.91.

(15)

You can also perform two operations of unapplying differencing once, to either differenced_twice or differenced_twice_2.

intermediateUnapplyDifference,differenced_twice

intermediate:=Time seriesWeekly Sales (differenced)8 rows of data:2010-01-15 - 2010-03-05

(16)

GetDataintermediate..3

33.1.22.

(17)

original_4UnapplyDifference,intermediate

original_4:=Time seriesWeekly Sales8 rows of data:2010-01-15 - 2010-03-05

(18)

GetDataoriginal_4..3

114.113.91.

(19)

intermediate_2UnapplyDifference,differenced_twice_2

intermediate_2:=Time seriesWeekly Sales (differenced)8 rows of data:2010-01-15 - 2010-03-05

(20)

GetDataintermediate_2..3

33.1.22.

(21)

original_5UnapplyDifference,intermediate_2

original_5:=Time seriesWeekly Sales8 rows of data:2010-01-15 - 2010-03-05

(22)

GetDataoriginal_5..3

114.113.91.

(23)

If you expect a biweekly pattern, you can difference with lag = 2.

differenced_lag2ApplyDifferencelag=2,sales

differenced_lag2:=Time seriesWeekly Sales (differenced)8 rows of data:2010-01-15 - 2010-03-05

(24)

GetDatadifferenced_lag2..3

36.34.23.

(25)

If one of the data points were missing, you can still do the transformation and back-transformation.

sales_numbers5undefined:sales_numbers

150147114113undefined16456393286

(26)

sales_missingTimeSeriessales_numbers,startdate=2010-01-01,frequency=weekly,header=Weekly Sales

sales_missing:=Time seriesWeekly Sales10 rows of data:2010-01-01 - 2010-03-05

(27)

differenced_lag2_missingApplyDifferencelag=2,sales_missing

differenced_lag2_missing:=Time seriesWeekly Sales (differenced)8 rows of data:2010-01-15 - 2010-03-05

(28)

GetDatadifferenced_lag2_missing

36.34.HFloatundefined51.58.125.24.47.

(29)

GetHeadersdifferenced_lag2_missing

Weekly Sales (differenced)

(30)

Specifying the origin option

• 

Consider the following time series.

tsTimeSeriesseq3..3,1,seq3..9,2

ts:=Time seriesdata set 1, data set 27 rows of data:2009 - 2015

(31)

GetDatats

3.3.2.1.1.1.0.3.1.5.2.7.3.9.

(32)
• 

If you try to unapply a differencing operation, Maple complains that it cannot find the origin.

UnapplyDifference,ts

Error, (in TimeSeriesAnalysis:-Difference:-Unapply) origin cannot be deduced; try specifying it using the 'origin' option

• 

With times=1 and lag=1 (the default), you need to specify a list of one 1x_2_ Matrix.

result1UnapplyDifference,ts,'origin'=Matrix1,2,2,3

result1:=Time seriesdata set 1, data set 27 rows of data:2009 - 2015

(33)

GetDataresult1

5.6.7.7.8.6.8.3.7.2.5.9.2.18.

(34)
• 

This can also be specified as just the list 2,3.

result2UnapplyDifference,ts,'origin'=2,3

result2:=Time seriesdata set 1, data set 27 rows of data:2009 - 2015

(35)

GetDataresult2

5.6.7.7.8.6.8.3.7.2.5.9.2.18.

(36)
• 

If you set lag=3, 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.

result3UnapplyDifferencelag=3,ts,'origin'=1,2,4|3,2,1

result3:=Time seriesdata set 1, data set 27 rows of data:2009 - 2015

(37)

GetDataresult3

4.6.4.1.5.2.4.3.3.6.3.9.1.6.

(38)
• 

If you set lag=3 and times=2, 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.

result4UnapplyDifferencelag=3,times=2,ts,'origin'=1,2,4|3,2,1,2,0,3|0,0,1

result4:=Time seriesdata set 1, data set 27 rows of data:2009 - 2015

(39)

GetDataresult4

6.6.4.1.2.1.10.9.7.7.5.10.11.3.

(40)

Compatibility

• 

The TimeSeriesAnalysis[Difference] command was introduced in Maple 18.

• 

For more information on Maple 18 changes, see Updates in Maple 18.

See Also

TimeSeriesAnalysis

TimeSeriesAnalysis[BoxCoxTransform]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam