Skip to content

Box–Cox transformation

A positive-data power family that includes natural logs. See the square-root case, fit lambda with its Jacobian, and avoid confusing inverse forecasts with means.

A Box–Cox transformation is a one-parameter family of monotone transformations of strictly positive data, combining power functions with a logarithmic limiting case. It can make level-dependent variability or a nonlinear response relationship easier to model. For a quant forecasting positive trading volume or volatility, that means choosing a modelling scale while keeping track of how predictions return to the original units.

A power family with a log at zero

For a positive numerical input yy and real parameter λ\lambda, the basic family is

gλ(y)={yλ−1λ,λ≠0,ln⁡y,λ=0,y>0.g_\lambda(y)= \begin{cases} \dfrac{y^\lambda-1}{\lambda},&\lambda\ne0,\\ \ln y,&\lambda=0, \end{cases} \qquad y>0.
The zero case is the natural logarithm, obtained continuously as λ→0\lambda\to0. All members preserve ordering because gλ′(y)=yλ−1>0g_\lambda'(y)=y^{\lambda-1}>0. SciPy's definition uses this positive-data convention.

Three landmarks help interpret the parameter:

ParameterTransformationWhat changes
λ=1\lambda=1y−1y-1A shift; distributional shape is unchanged
λ=1/2\lambda=1/22(y−1)2(\sqrt y-1)A scaled, shifted square root
λ=0\lambda=0ln⁡y\ln yMultiplicative ratios become additive differences

Calling λ=1\lambda=1 the “identity case” refers to unchanged shape: the formula returns y−1y-1, not exactly yy.

Take synthetic positive inputs 1,4,91,4,9, expressed as dimensionless ratios to a fixed reference level. At λ=1/2\lambda=1/2,

g1/2(1)=0,g1/2(4)=2,g1/2(9)=4.g_{1/2}(1)=0,\qquad g_{1/2}(4)=2,\qquad g_{1/2}(9)=4.

The original gaps are 3 and 5; the transformed gaps are both 2. With λ=0\lambda=0, the outputs instead are 0,ln⁡4,ln⁡90,\ln4,\ln9, approximately 0,1.386294,2.1972250,1.386294,2.197225. Equal spacing in this tiny example is arithmetic, not evidence that the population is Gaussian.

Three Box–Cox curves for positive dimensionless inputs. At y equal to 1, 4 and 9, lambda 0.5 gives 0, 2 and 4; lambda 0 gives 0, 1.386 and 2.197; lambda 1 gives 0, 3 and 8. The log and square-root members compress larger inputs more than lambda 1.
Three Box–Cox curves for positive dimensionless inputs. At y equal to 1, 4 and 9, lambda 0.5 gives 0, 2 and 4; lambda 0 gives 0, 1.386 and 2.197; lambda 1 gives 0, 3 and 8. The log and square-root members compress larger inputs more than lambda 1.
Original synthetic scale comparison. The square-root member makes these particular three inputs equally spaced; three points establish neither a distribution nor a fitted transformation parameter.

Zeros and negative observations fall outside this basic family. Transforming y+cy+c is a different specification: state the shift and ensure positivity for every observation to which it will be applied. A shift can change the selected power and the interpretation. Changing units changes transformed values and coefficient units; declaring a fixed reference scale makes the input convention explicit. A pure unit conversion can leave the fitted λ\lambda unchanged when the regression includes an intercept and the complete likelihood is used; the numerical coefficients still refer to the declared transformed scale. An added shift has no such general invariance.

Fit the model, not just the transformed variance

The classical motivation is a response scale on which a linear model with constant error variance and approximately Gaussian errors is useful. Box and Cox's original summary distinguishes normality, constant variance and additivity as separate concerns.
For a fixed design matrix XX, write the working model as gλ(yi)=xi⊤β+εig_\lambda(y_i)=x_i^\top\beta+\varepsilon_i, with independent errors of common variance σ2\sigma^2. When comparing λ\lambda by Gaussian maximum likelihood, the density must be expressed on the original observed-data scale. Its change-of-variable factor is
Jλ=∏i=1nyiλ−1.J_\lambda=\prod_{i=1}^{n}y_i^{\lambda-1}.

After fitting β\beta and profiling out σ2\sigma^2, the usual working profile log-likelihood is

ℓp(λ)=−n2ln⁡ ⁣(SSE⁡λn)+(λ−1)∑i=1nln⁡yi+C,\ell_p(\lambda) =-\frac n2\ln\!\left(\frac{\operatorname{SSE}_\lambda}{n}\right) +(\lambda-1)\sum_{i=1}^{n}\ln y_i+C,
where SSE⁡λ\operatorname{SSE}_\lambda is the residual sum of squares from refitting the same regression specification at that λ\lambda, and CC is independent of λ\lambda. SciPy documents the intercept-only version, where residuals are deviations from the transformed sample mean. Minimising transformed variance alone omits the Jacobian term and compares incompatible scales.

For the three illustrative inputs, an intercept-only calculation gives:

Candidate λ\lambdaResidual sum of squaresℓp(λ)−C\ell_p(\lambda)-C
002.4690722.469072−3.291364-3.291364
0.50.588−3.263003-3.263003

The log has the smaller residual variance, yet the square-root candidate has the larger complete criterion. This compares two stipulated candidates; it does not estimate a reliable power from three observations or establish the global optimum.

The expression is a working Gaussian criterion. For nonzero λ\lambda, the transformed positive response has a bound, so an unrestricted normal model is not literally supported everywhere; a model that explicitly truncates the normal distribution needs its corresponding normalisation. More generally, the transformation supplies no guarantee of Gaussian tails, constant variance, independence or forecast accuracy. Inspect model residuals, rather than judging success only from a histogram of the response.
Residual Diagnostics and Model Checking develops residual-versus-fitted plots and QQ plots for these checks (public preview; full lesson requires membership).

Returning to the original scale

For a transformed value zz, the inverse is

gλ−1(z)={(1+λz)1/λ,λ≠0,1+λz>0,ez,λ=0.g_\lambda^{-1}(z)= \begin{cases} (1+\lambda z)^{1/\lambda},&\lambda\ne0,\quad1+\lambda z>0,\\ e^z,&\lambda=0. \end{cases}
Inverting a conditional expectation generally does not recover the original-scale conditional mean:
gλ−1 ⁣(E[gλ(Y)∣x])≠E[Y∣x].g_\lambda^{-1}\!\left(\mathbb E[g_\lambda(Y)\mid x]\right) \ne\mathbb E[Y\mid x].
For a concrete assumed lognormal model, let ln⁡Y∣x∼N(ln⁡100,0.16)\ln Y\mid x\sim\mathcal N(\ln100,0.16), with positive YY measured on a fixed numerical scale. Exponentiating the log-scale mean gives 100, the conditional median. The conditional mean instead is
E[Y∣x]=eln⁡100+0.16/2=100e0.08≈108.328707.\mathbb E[Y\mid x]=e^{\ln100+0.16/2} =100e^{0.08}\approx108.328707.
This exact correction uses the conditional lognormal assumption and its variance, not just the fitted log mean. The NIST lognormal formulas identify the distinction between median and mean; Forecasting: Principles and Practice, §5.6 explains the forecasting consequence. Other powers or residual distributions require an appropriate distributional calculation or integration. A transformation is part of the model, including its return journey to the quantity being forecast.

Sources

Last updated
  • box cox
  • power transformation
  • regression
  • likelihood
  • forecasting
← Back to the glossaryBack to top ↑