DescTools (version 0.99.14)

BoxCox: Box Cox Transformation

Description

BoxCox() returns a transformation of the input variable using a Box-Cox transformation. BoxCoxInv() reverses the transformation.

Usage

BoxCox(x, lambda)
BoxCoxInv(x, lambda)

Arguments

x
a numeric vector
lambda
transformation parameter

Value

  • a numeric vector of the same length as x.

Details

The Box-Cox transformation is given by $$f_\lambda(x) =\frac{x^\lambda - 1}{\lambda}$$ if $\lambda\ne0$. For $\lambda=0$, $$f_0(x)=\log(x)$$.

References

Box, G. E. P. and Cox, D. R. (1964) An analysis of transformations. JRSS B 26 211--246.

See Also

Use BoxCoxLambda or boxcox in library(MASS) to find optimal lambda values.

Examples

Run this code
# example by Greg Snow
x <- rlnorm(500, 3, 2)

par(mfrow=c(2,2))
qqnorm(x, main="Lognormal")
qqnorm(BoxCox(x, 1/2), main="BoxCox(lambda=0.5)")
qqnorm(BoxCox(x, 0), main="BoxCox(lambda=0)")

hist(BoxCox(x, 0))

bx <- BoxCox( x, lambda = BoxCoxLambda(x) )

Run the code above in your browser using DataCamp Workspace