box_cox: Box-Cox transform specification

View source: R/transform.R

box_coxR Documentation

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, ...)

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.

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).

Value

A list with the transform and inverse functions.

Note

The returned transform function will take additional argument “frequency” which determines whether a series is seasonal or not. When estimating lambda (when setting this to NA), a series with frequency > 1 will first be de-seasonalized using an STL decomposition.

Author(s)

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

References

\insertRef

Box1964tsaux
\insertRefVelilla1993tsaux
\insertRefGuerrero1993tsaux

Examples


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)


tsaux documentation built on April 4, 2025, 3:08 a.m.