Learn R Programming

tsaux (version 1.0.0)

box_cox: Box-Cox transform specification

Description

Creates a specification for the Box Cox transformation.

Usage

box_cox(lambda = NA, lower = 0, upper = 1.5, multivariate = FALSE, ...)

Value

A list with the transform and inverse functions.

Arguments

lambda

the power parameters. If NA then it will automatically calculate the optimal parameter using the method of Guerrero (for univariate case) else for the multivariate case, the method of Velilla (1993) which is implemented in the car package of John Fox. This targets a transformation to multivariate normality. If any of the inputs has a frequency other than 1, then an stl decomposition is first applied and the seasonal component removed prior to the estimation in order to avoid confounding the estimation by seasonality. It is also possible to pass a vector equal to the number of columns of the dataset (with numeric values mixed with NAs which will calculate the univariate optimal lambda).

lower

optional parameter lower bound for cases when it is calculated.

upper

optional parameter upper bound for cases when it is calculated.

multivariate

flag for the multivariate case. If lambda is a single parameter, then that is applied to all series (including NA which results in the multivariate transformation described above).

...

not currently used.

Author

Alexios Galanos for the BoxCox function.
John Fox for the powerTransform function used in the multivariate case.

Details

The function returns a list of 2 functions called “transform” and “inverse” which can be called with a data object and a frequency to calculate the transformed values. The auto_lambda function uses the method of Guerrero(1993).

References

Box1964tsaux
Velilla1993tsaux
Guerrero1993tsaux

Examples

Run this code

y = cumprod(c(1, 1 + rnorm(100,0.01, 0.005)))
B = box_cox(lambda = NA)
yt = B$transform(y, frequency = 1)
lambda = attr(yt,"lambda")
ye = B$inverse(yt, lambda)

Run the code above in your browser using DataLab