Box-Cox transformation - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Statistics : Time Series Analysis Package : TimeSeriesAnalysis/BoxCoxTransform

TimeSeriesAnalysis[BoxCoxTransform] - Box-Cox transformation

TimeSeriesAnalysis[LogTransform] - Log transformation

Calling Sequence

Apply(BoxCoxTransform, timeseries)

Apply(BoxCoxTransform(lambda = lm, base = b, geometricmean = g, shift = s), timeseries)

Apply(LogTransform, timeseries)

Apply(LogTransform(base = b, geometricmean = g, shift = s), timeseries)

Unapply(BoxCoxTransform, forecast)

Unapply(BoxCoxTransform(lambda = lm, base = b, geometricmean = g, shift = s), forecast)

Unapply(LogTransform, forecast)

Unapply(LogTransform(base = b, geometricmean = g, shift = s), forecast)

Parameters

timeseries

-

TimeSeries data set

forecast

-

TimeSeries data set, typically obtained from a forecasting method

lm

-

(optional) parameter of the Box-Cox transform, typically between 2 and 2

b

-

(optional) if lm is 0, the base of the logarithm

g

-

(optional) true or false, indicating whether or not to correct the scale of the results using the geometric mean

s

-

(optional) constant shift applied before the Box-Cox transform is applied

Description

• 

The Box-Cox transformation takes a time series and replaces each value Ti with the value Tiλ1λ. If the parameter λ is set to 0, the resulting value is LimitTiλ1λ,λ=0=lnTi.

• 

Apply this transformation to a time series using the Apply command. Translate transformed information, such as a forecast from transformed data, back to the original domain by using the Unapply command.

• 

By default, the λ parameter has value 0, and the transformation is the log transformation (the natural logarithm, with base ⅇ). By supplying the λ option, you can set this parameter to a different value. The command LogTransform is the same as BoxCoxTransform, except you cannot supply the lambda parameter: it is fixed to always be 0.

• 

If λ=0, then you can choose to use a different base for the logarithm by supplying the base option. For example, to obtain the common logarithm, supply the option base=10. It is an error to supply the base option if λ is set to a value different from 0. The default base is ⅇ.

• 

Negative data points result in undefined values. To prevent this from happening, you can supply the shift=s option. The value s is added to each data point before the transformation is applied. By default, s is 0.

• 

Applying a Box-Cox transformation may have the transformed time series being of a different order of magnitude than the original time series, and Box-Cox transformations with different values for the parameter λ may also have different orders of magnitude. If this is undesirable, for example when comparing an absolute measure of error involving the results of different Box-Cox transformations, you can supply the geometricmean = true option. This computes the geometric mean of each data set after the shift is applied but before the transformation is applied; then after applying the transformation, each data value is multiplied by this geometric mean, raised to the power 1λ. This can be viewed as preserving the units of measurement that the time series data is expressed in.

Examples

withTimeSeriesAnalysis:

sales:=TimeSeries150,147,114,113,91,164,56,39,32,86,startdate=2010-01-01,frequency=weekly,header=Weekly Sales

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

(1)

GetDatasales..4

150.147.114.113.

(2)

Here are the log-transformed data.

log_sales:=ApplyLogTransform,sales

log_sales:=Time seriesLogarithm of Weekly Sales10 rows of data:2010-01-01 - 2010-03-05

(3)

GetDatalog_sales..4

5.010635294096264.990432586778744.736198448394504.72738781871234

(4)

Reconstructing the original data:

original:=UnapplyLogTransform,log_sales

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

(5)

GetDataoriginal..4

150.000000000000147.000000000000114.000000000000113.000000000000

(6)

Apply the logarithm with base 10 instead.

common_log_sales:=ApplyLogTransformbase=10,sales

common_log_sales:=Time seriesLogarithm of Weekly Sales10 rows of data:2010-01-01 - 2010-03-05

(7)

GetDatacommon_log_sales..4

2.176091259055682.167317334748182.056904851336472.05307844348342

(8)

original_2:=UnapplyLogTransformbase=10,common_log_sales

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

(9)

GetDataoriginal_2..4

150.000000000000147.000000000000114.000000000000113.000000000000

(10)

We now apply the Box-Cox transformation with parameter λ=23 to the sales data. We also apply the geometric mean correction.

boxcox:=ApplyBoxCoxTransformλ=23,geometricmean=true,sales

boxcox:=Time seriesBox-Cox transform of Weekly Sales10 rows of data:2010-01-01 - 2010-03-05

(11)

GetDataboxcox..4

181.145998663384178.633601318965149.746747925208148.830791928663

(12)

original_3:=UnapplyBoxCoxTransformλ=23,geometricmean=true,boxcox

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

(13)

GetDataoriginal_3..4

150.000000000000147.000000000000114.000000000000113.000000000000

(14)

Temperature data in Celsius is sometimes negative. These were the daily minimum and maximum temperatures in Waterloo, Ontario, Canada, averaged over a month.

average_temperature_matrix:=12|5,11|2,6|2,1|11,9|18,12|23,16|29,14|26,10|21,4|14,1|10,4|3,7|1,5|2,0|12,0|12,9|22,13|25,15|29,13|26,9|21,5|13,2|6,3|3

average_temperature_matrix:= 24 x 2 MatrixData Type: anythingStorage: rectangularOrder: Fortran_order

(15)

average_temperatures:=TimeSeriesaverage_temperature_matrix,startdate=2011-01-01,frequency=monthly,headers=average minimum temperature,average maximum temperature

average_temperatures:=Time seriesaverage minimum temperature, average maximum temperature24 rows of data:2011-01-01 - 2012-12-01

(16)

GetDataaverage_temperatures..4

12.5.11.2.6.2.1.11.

(17)

In order to apply the Box-Cox transform, we need to shift the data by a number greater than minus the minimum value, 12.

transformation:=BoxCoxTransformshift=20,λ=12,'geometricmean'

transformation:=<< Box-Cox transformation with parameter 1/2 >>

(18)

transformed_temperatures:=Applytransformation&comma;average_temperatures

transformed_temperatures:=Time seriesBox-Cox transform of average minimum temperature, Box-Cox transform of average maximum temperature24 rows of data:2011-01-01 - 2012-12-01

(19)

GetDatatransformed_temperatures..4

17.011378367377732.353547586475518.607663534568436.516372402592125.507919090076841.558904981799533.331681559430551.4389969826016

(20)

original_temperatures:=Unapplytransformation&comma;transformed_temperatures

original_temperatures:=Time seriesaverage minimum temperature, average maximum temperature24 rows of data:2011-01-01 - 2012-12-01

(21)

GetDataoriginal_temperatures..4

12.00000000000005.0000000000000011.2.000000000000016.1.999999999999990.99999999999998911.0000000000000

(22)

See Also

TimeSeriesAnalysis, TimeSeriesAnalysis[Difference]


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