Last data update: 2014.03.03

R: Box Cox Transformation
BoxCoxR Documentation

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

Details

The Box-Cox transformation is given by

f(x;lambda)=(x^lambda - 1)/lambda

if lambda is not equal to 0. For lambda=0,

f(x;0)=log(x)

.

Value

a numeric vector of the same length as x.

Note

These two functions are borrowed from library(forecast).

Author(s)

Rob J Hyndman <rob.hyndman@monash.edu>

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

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

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DescTools)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DescTools/BoxCox.Rd_%03d_medium.png", width=480, height=480)
> ### Name: BoxCox
> ### Title: Box Cox Transformation
> ### Aliases: BoxCox BoxCoxInv
> ### Keywords: univar
> 
> ### ** Examples
> 
> # 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) )
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>