Box-Cox transformation
[transdat,lambda]=boxcox(data) transdat=boxcox(data,lambda)
a m-by-1 matrix of doubles, greater or equal to zero, the data to transform
a m-by-1 matrix of doubles, the transformed data
a m-by-1 matrix of doubles, the estimated lambda
[transdat,lambda]=boxcox(data) estimates the optimal lambda parameter and applies the Box-Cox transformation.
transdat=boxcox(data,lambda) applies the Box-Cox transformation using the given value of lambda.
The Box-Cox transformation is defined by
if lambda is nonzero and
if lambda=0.
If lambda is not provided, the estimate of lambda is done with the boxcoxestimate function.
If the lambda parameter is estimated from the data, the transformed data has two interesting properties. First, the distribution of the transformed data has a variance which is closer to constant, i.e. it stabilizes the variance. Furthermore, the transformed data has a distribution which may be closer to the normal distribution.
This transformation can only be applied to positive data.
Uses a robust implementation which is accurate even when lambda is close to zero.
data = [0.15 0.09 0.18 0.10 0.05 0.12 0.08]; lambda=0.7; transdat=boxcox(data,lambda) // Estimates lambda [transdat,lambda]=boxcox(data) // See chi-square random numbers data=distfun_chi2rnd(2,100,1); scf(); subplot(1,2,1); histo(data,"Normalization","pdf"); xlabel("Chi-Square Data"); ylabel("PDF"); // Applies Box-Cox : the transformed data // is closer to the normal distribution [transdat,lambda]=boxcox(data) subplot(1,2,2); histo(transdat,"Normalization","pdf") xlabel("BoxCox(Chi-Square Data)") ylabel("PDF") title(msprintf("Box-Cox with lambda=%.2f",lambda)) // Check accuracy when lambda is close to zero transdat=boxcox(0.15,1.e-20) exact=-1.897119984885881302 | ![]() | ![]() |
http://www.itl.nist.gov/div898/handbook/pmc/section5/pmc52.htm
https://en.wikipedia.org/wiki/Power_transform
https://www.unistat.com/guide/box-cox-regression/
http://www.stat.missouri.edu/~amicheas/stat7110/boxcox.html
http://robjhyndman.com/talks/RevolutionR/7-Transformations.pdf