BoxCox | R Documentation |
BoxCox()
returns a transformation of the input variable using a Box-Cox transformation.
BoxCoxInv()
reverses the transformation.
BoxCox(x, lambda)
BoxCoxInv(x, lambda)
x |
a numeric vector |
lambda |
transformation parameter |
The Box-Cox transformation is given by
f_\lambda(x) =
\left\{\begin{array}{ll}
\frac{x^\lambda - 1}{\lambda} &\textup{for }\lambda \neq 0\\
log(x) &\textup{for }\lambda = 0
\end{array}\right.
a numeric vector of the same length as x.
These two functions are borrowed from library(forecast)
.
Rob J Hyndman <rob.hyndman@monash.edu>
Box, G. E. P. and Cox, D. R. (1964) An analysis of transformations. JRSS B 26 211–246.
Use BoxCoxLambda
or boxcox
in library(MASS)
to find optimal lambda values.
# 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)")
PlotFdist(BoxCox(x, 0))
bx <- BoxCox(x, lambda = BoxCoxLambda(x) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.