Box-Cox transformation: how to choose lambda, with an example

Updated

The Box-Cox transformation raises positive data to a power λ (lambda) chosen so that the transformed values follow a normal distribution as closely as possible. It turns many right-skewed data sets into nearly normal ones, so that normal-based tools such as capability analysis and control charts can be used on the transformed scale. λ = 0.5 is a square root, λ = 0 a natural logarithm, λ = −1 a reciprocal and λ = 1 leaves the shape unchanged.

When to use it

  • The data are positive and skewed, and a normality test rejects the normal distribution: leakage current, impurity levels, cycle times, roughness, particle counts per volume.
  • You want to run a normal capability analysis or a control chart and keep the familiar indices and rules.
  • The skewness comes from the nature of the measurement, not from a special cause or a mixture of two processes.
  • If the data include zero or negative values, or the shape is not a simple skew, consider the Johnson transformation instead.

How it works

The transformation, in the form Box and Cox published in 1964, is:

y = (x^λ − 1) / λ for λ ≠ 0 y = ln(x) for λ = 0

Subtracting 1 and dividing by λ only shifts and rescales the values, so many programs report the simpler y = x^λ. For λ > 0, both give the same capability indices.

λ is chosen by maximum likelihood: for each candidate λ, transform the data, and compute

ℓ(λ) = −(n/2) ln σ̂²(λ) + (λ − 1) Σ ln xᵢ

where σ̂²(λ) is the variance (divided by n) of the transformed values. The second term accounts for the stretching of the scale. The λ with the largest ℓ wins. An equivalent recipe minimizes the standard deviation of the transformed values after rescaling them by the geometric mean. An approximate 95% confidence interval for λ contains every value whose ℓ is within 1.92 (half the 95th percentile of chi-square with 1 degree of freedom) of the maximum.

In practice you round λ to a convenient value inside the interval, such as 0.5 or 0, because it is easier to explain and changes little.

Transform the specification limits too. Capability on the transformed scale compares the transformed data with the transformed limits: USL* = USL^λ. When λ is negative, x^λ reverses the order of the values, so the upper limit becomes the lower limit on the new scale.

Example

A capacitor line tests leakage current after a two-minute charge. The specification is at most 5.0 µA. These are 30 capacitors, in µA:

1.92, 1.90, 2.58, 1.13, 1.94, 1.60, 0.99, 1.17, 1.61, 0.95, 1.58, 3.11, 0.16, 1.42, 1.78, 1.47, 0.75, 4.35, 2.28, 0.49, 1.68, 1.02, 0.85, 1.67, 1.15, 2.56, 0.93, 1.15, 0.77, 1.56

On the original scale, the mean is 1.551 µA and the standard deviation 0.834 µA. A normal capability analysis would give PPU = (5.0 − 1.551)/(3 × 0.834) = 1.38. But the Anderson-Darling test rejects normality (A² = 0.799, p = 0.034); the histogram has a long right tail.

The Box-Cox log-likelihood peaks at λ = 0.433, with a 95% interval from 0.03 to 0.88. The chart shows ℓ(λ) − ℓ(0.433); values above the cutoff line at −1.92 are inside the interval.

Box-Cox log-likelihood relative to its maximum-10-50Relative log-likelihoodℓ(λ) − ℓmax95% cutoff-0.5-0.2500.250.50.7511.251.5λ
Box-Cox log-likelihood relative to its maximum

λ = 1 (no transformation) and λ = 0 (logarithm) are both outside the interval; λ = 0.5, the square root, is inside. With y = √x:

  • The transformed data have mean 1.2029 and standard deviation 0.3275, and pass the normality test (A² = 0.354, p = 0.44).
  • The transformed limit is USL* = √5.0 = 2.2361.
  • PPU = (2.2361 − 1.2029) / (3 × 0.3275) = 1.05, with about 800 PPM expected above 5.0 µA.
Square root of leakage current051015FrequencyUSL012√(leakage current)
Square root of leakage current

Using the unrounded λ = 0.433 gives PPU = 1.01 and about 1,260 PPM: the same conclusion.

How to read the results

  • The normal answer was too optimistic. On the raw data the process looked capable (1.38, about 18 PPM). After the transformation it is not (1.05, about 800 PPM), because the right tail is longer than a normal curve allows.
  • The interval for λ matters more than λ itself. Any value from about 0.03 to 0.88 is consistent with the data. Pick a round value inside it and say so in the report.
  • Check the result, not only the λ. The transformed data should pass a normality test and look straight on a probability plot. If they do not, Box-Cox is not the right tool.
  • Report in the original units. Customers think in µA. State the specification, the transformation used and the expected PPM above 5.0 µA.

Common mistakes

  • Transforming the data but not the limits. Comparing √x with 5.0 instead of √5.0 gives meaningless indices.
  • Forgetting the order flips for negative λ. With λ = −1, a large x becomes a small 1/x, and the USL becomes a lower limit.
  • Using it on data with zeros. x^λ and ln x are undefined or infinite at zero. Adding a constant to make the data positive changes the shape and the result; a Johnson transformation or a distribution fit is usually a cleaner option.
  • Transforming away a real problem. A mixture of two machines can look skewed. Box-Cox will happily produce a λ, but the right action is to separate the streams.

Frequently asked questions

What do the common lambda values mean?

λ = 2 squares the data, 1 leaves them as they are, 0.5 takes the square root, 0 the natural logarithm, −0.5 the reciprocal square root and −1 the reciprocal. Values between 0 and 1 suit right-skewed data, the most common case.

Does the transformation change Cpk?

It changes the estimate, because the indices are computed on a scale where the normal model fits. For λ > 0, the version x^λ and the version (x^λ − 1)/λ give the same indices.

Can I use a control chart on transformed data?

Yes. Chart the transformed values with the usual limits, then convert the limits back with x = y^(1/λ) if you want to show them in original units. The limits will be asymmetric around the center line, which reflects the skewness.

Why not just fit a lognormal distribution?

You can; λ = 0 is the same as a lognormal model. Box-Cox searches a whole family of powers and lets the data choose. Here it rejected the logarithm in favor of a milder transformation.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab