TimeSeriesAnalysis
BoxCoxTransform
Box-Cox transformation
LogTransform
Log transformation
Calling Sequence
Parameters
Description
Examples
Compatibility
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)
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
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 limλ→0⁡Tiλ−1λ=ln⁡Ti.
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.
with⁡TimeSeriesAnalysis:
sales≔TimeSeries⁡150,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
GetData⁡sales..4
150.147.114.113.
Here are the log-transformed data.
log_sales≔Apply⁡LogTransform,sales
log_sales≔Time seriesLogarithm of Weekly Sales10 rows of data:2010-01-01 - 2010-03-05
GetData⁡log_sales..4
5.010635294096264.990432586778744.736198448394504.72738781871234
Reconstructing the original data:
original≔Unapply⁡LogTransform,log_sales
original≔Time seriesWeekly Sales10 rows of data:2010-01-01 - 2010-03-05
GetData⁡original..4
150.000000000000147.000000000000114.000000000000113.000000000000
Apply the logarithm with base 10 instead.
common_log_sales≔Apply⁡LogTransform⁡base=10,sales
common_log_sales≔Time seriesLogarithm of Weekly Sales10 rows of data:2010-01-01 - 2010-03-05
GetData⁡common_log_sales..4
2.176091259055682.167317334748182.056904851336472.05307844348342
original_2≔Unapply⁡LogTransform⁡base=10,common_log_sales
original_2≔Time seriesWeekly Sales10 rows of data:2010-01-01 - 2010-03-05
GetData⁡original_2..4
We now apply the Box-Cox transformation with parameter λ=23 to the sales data. We also apply the geometric mean correction.
boxcox≔Apply⁡BoxCoxTransform⁡λ=23,geometricmean=true,sales
boxcox≔Time seriesBox-Cox transform of Weekly Sales10 rows of data:2010-01-01 - 2010-03-05
GetData⁡boxcox..4
181.145998663384178.633601318965149.746747925208148.830791928663
original_3≔Unapply⁡BoxCoxTransform⁡λ=23,geometricmean=true,boxcox
original_3≔Time seriesWeekly Sales10 rows of data:2010-01-01 - 2010-03-05
GetData⁡original_3..4
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_temperatures≔TimeSeries⁡average_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
GetData⁡average_temperatures..4
−12.−5.−11.−2.−6.2.1.11.
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≔BoxCoxTransform⁡shift=20,λ=12,geometricmean
transformation≔<< Box-Cox transformation with parameter 1/2 >>
transformed_temperatures≔Apply⁡transformation,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
GetData⁡transformed_temperatures..4
17.011378367377732.353547586475518.607663534568436.516372402592125.507919090076841.558904981799533.331681559430551.4389969826016
original_temperatures≔Unapply⁡transformation,transformed_temperatures
original_temperatures≔Time seriesaverage minimum temperature, average maximum temperature24 rows of data:2011-01-01 - 2012-12-01
GetData⁡original_temperatures..4
−12.0000000000000−5.00000000000000−11.−2.00000000000001−6.1.999999999999990.99999999999998911.0000000000000
The TimeSeriesAnalysis[BoxCoxTransform] and TimeSeriesAnalysis[LogTransform] commands were introduced in Maple 18.
For more information on Maple 18 changes, see Updates in Maple 18.
See Also
TimeSeriesAnalysis[Difference]
Download Help Document