boxcoxTransform(x, lambda, eps = .Machine$double.eps)
lambda
is less
than eps
, lambda is assumed to be 0 for the Box-Cox transformation.
The default value is eps=.Machine$double.eps
.boxcox
for details.
Note that for non-zero values of $\lambda$, instead of using the formula of
Box and Cox in Equation (1), you may simply use the power transformation:
$$Y = X^\lambda \;\;\;\;\;\; (2)$$
since these two equations differ only by a scale difference and origin shift,
and the essential character of the transformed distribution remains unchanged.
The value $\lambda=1$ corresponds to no transformation. Values of
$\lambda$ less than 1 shrink large values of $X$, and are therefore
useful for transforming positively-skewed (right-skewed) data. Values of
$\lambda$ larger than 1 inflate large values of $X$, and are therefore
useful for transforming negatively-skewed (left-skewed) data
(Helsel and Hirsch, 1992, pp.13-14; Johnson and Wichern, 2007, p.193).
Commonly used values of $\lambda$ include 0 (log transformation),
0.5 (square-root transformation), -1 (reciprocal), and -0.5 (reciprocal root).
It is often recommend that when dealing with several similar data sets, it is best
to find a common transformation that works reasonably well for all the data sets,
rather than using slightly different transformations for each data set
(Helsel and Hirsch, 1992, p.14; Shumway et al., 1989).boxcox
, Data Transformations, Goodness-of-Fit Tests.# Generate 30 observations from a lognormal distribution with
# mean=10 and cv=2, then look at some normal quantile-quantile
# plots for various transformations.
# (Note: the call to set.seed simply allows you to reproduce this example.)
set.seed(250)
x <- rlnormAlt(30, mean = 10, cv = 2)
dev.new()
qqPlot(x, add.line = TRUE)
dev.new()
qqPlot(boxcoxTransform(x, lambda = 0.5), add.line = TRUE)
dev.new()
qqPlot(boxcoxTransform(x, lambda = 0), add.line = TRUE)
# Clean up
#---------
rm(x)
Run the code above in your browser using DataLab