Tutorials › Exam PA - Predictive Analytics › Yeo-Johnson Transformations With Zeros and Negatives

Exam PA · Transformations, Scaling, and Binning · Tutorial 203 of 966

Yeo-Johnson Transformations With Zeros and Negatives

Use the Yeo-Johnson family to transform predictors that include zero or negative values, and understand how the parameter changes each branch and the resulting distribution.

Intermediate 11 min read

What You'll Learn

  • State both branches of the Yeo-Johnson transformation and their domains.
  • Evaluate the special cases at parameter values zero, one, and two.
  • Explain why the transformation is continuous and strictly increasing.
  • Compare transformed values and distribution summaries across parameter choices.
  • Recognize calculation and interpretation traps when using the family.

Why Use the Yeo-Johnson Transformation?

A predictor may contain negative values or zeros because it records a change from a baseline, a centered measurement, or a difference between two quantities. The Box-Cox family is defined for strictly positive data, so it cannot be applied directly to such a predictor without an additional shift. The Yeo-Johnson transformation is a power family defined on the entire real line. Its separate branches allow it to transform positive and negative values while retaining zero as zero.

The transformation changes the scale and shape of a predictor; it does not change the observed ordering of its values. The parameter \(\lambda\) controls the curvature, and the positive and negative branches respond differently to it. As with other predictor transformations, the appropriate choice depends on the modeling objective and the observed data. A transformed distribution that looks more symmetric is not, by itself, proof that a model is better.

Definition: For a real-valued predictor \(x\) and real parameter \(\lambda\), the Yeo-Johnson transformation is $$ T_\lambda(x)= \begin{cases} \displaystyle \frac{(x+1)^\lambda-1}{\lambda}, & x\geq 0,\ \lambda\neq 0,\\[6pt] \log(x+1), & x\geq 0,\ \lambda=0,\\[6pt] \displaystyle -\frac{(1-x)^{2-\lambda}-1}{2-\lambda}, & x<0,\ \lambda\neq 2,\\[6pt] -\log(1-x), & x<0,\ \lambda=2. \end{cases} $$ The logarithm is the natural logarithm. The two special parameter cases are defined by limits of the corresponding power expressions.

Understanding the Two Branches

For nonnegative \(x\), the formula uses the power \(\lambda\) and the shifted quantity \(x+1\). For negative \(x\), it uses the power \(2-\lambda\) and the positive quantity \(1-x\), with a leading negative sign. Since \(x+1\geq 1\) in the first branch and \(1-x>1\) in the second, the real-valued powers are defined for every real \(\lambda\). The transformation also has \(T_\lambda(0)=0\).

The special cases must be handled on their own branches. When \(\lambda=0\), the nonnegative branch is logarithmic; the negative branch is still a power expression. When \(\lambda=2\), the negative branch is logarithmic; the nonnegative branch is still a power expression. In particular, the parameter value alone does not make the entire transformation logarithmic.

Worked Example: Evaluating Both Branches at Lambda Zero

A hypothetical portfolio predictor records a change in a measured quantity, in units relative to a reference value. Calculate the transformed values for \(x=3\) and \(x=-3\) when \(\lambda=0\). Give results to four decimal places.

Method. Since \(\lambda=0\), use the logarithmic formula for the positive value and the power formula with exponent \(2-\lambda=2\) for the negative value.

For \(x=3\), the nonnegative branch gives \(T_0(3)=\log(3+1)=\log 4=1.386294\ldots\), or 1.3863.

For \(x=-3\), the negative branch gives \(T_0(-3)=-\{(1-(-3))^2-1\}/2\). The base is \(4\), so \(4^2=16\). Therefore, \(T_0(-3)=-(16-1)/2=-15/2=-7.5000\).

Check and common mistake. The negative result is less than zero, as expected from the increasing transformation and \(T_0(0)=0\). Substituting \(x=-2\) would give \(-4.0000\); using that value for \(x=-3\) is an input-substitution error.

Special Cases and the Identity Transformation

Some parameter values simplify the family and provide useful checks on calculations. When \(\lambda=1\), both branches reduce to the original predictor. When \(\lambda=2\), negative values use a logarithm while nonnegative values use a quadratic expression. These simplifications also make clear why it is important to identify the sign of \(x\) before choosing a branch.

Worked Example: Applying the Lambda-Two Branches

For a hypothetical predictor measuring deviations from a target, calculate \(T_2(-2)\), \(T_2(0)\), and \(T_2(2)\). Round to four decimal places.

Method. At \(\lambda=2\), use \(-\log(1-x)\) for the negative value and the power formula with exponent 2 for the positive value.

For \(x=-2\), \(T_2(-2)=-\log(1-(-2))=-\log 3=-1.098612\ldots\), or -1.0986.

At zero, either the definition or direct substitution gives \(T_2(0)=0\).

For \(x=2\), \(T_2(2)=\{(2+1)^2-1\}/2=(9-1)/2=4.0000\).

Check and common mistake. The negative result uses a logarithm, but the positive result does not. Applying the logarithmic formula to \(x=2\) would incorrectly give \(\log 3\) instead of \(4\).

Key result: When \(\lambda=1\), \(T_1(x)=x\) for every real \(x\). For \(x\geq0\), the expression is \(((x+1)-1)/1=x\). For \(x<0\), it is \(-((1-x)-1)/1=-(-x)=x\).

Why the Transformation Preserves Ordering

For a predictor transformation to preserve the direction of comparisons, larger original values should map to larger transformed values. The Yeo-Johnson family has this property for every real \(\lambda\). A derivative calculation shows why.

For \(x>0\) and \(\lambda\neq0\), differentiating the positive branch gives \((1+x)^{\lambda-1}\). At \(\lambda=0\), differentiating \(\log(1+x)\) gives \(1/(1+x)\), which is the same expression with \(\lambda=0\). For \(x<0\) and \(\lambda\neq2\), differentiating the negative branch gives \((1-x)^{1-\lambda}\); at \(\lambda=2\), differentiating \(-\log(1-x)\) gives \(1/(1-x)\), again the same expression with \(\lambda=2\). Thus,

$$ T'_\lambda(x)= \begin{cases} (1+x)^{\lambda-1}, & x>0,\\ (1-x)^{1-\lambda}, & x<0. \end{cases} $$

Both bases are positive, so both derivatives are positive. At zero the one-sided derivatives are each 1. Consequently the transformation is continuous at zero and strictly increasing across its domain. This is a useful check: a negative input must transform to a negative value, zero remains zero, and a positive input transforms to a positive value.

The special logarithmic formulas follow from limits. For the nonnegative branch, set \(a=\log(1+x)\), so that \((1+x)^\lambda=e^{\lambda a}\). Then \((e^{\lambda a}-1)/\lambda\) tends to \(a\) as \(\lambda\) tends to zero, giving \(\log(1+x)\). For the negative branch, set \(b=\log(1-x)\); as \(2-\lambda\) tends to zero, \(\{(1-x)^{2-\lambda}-1\}/(2-\lambda)\) tends to \(b\). The leading negative sign therefore gives \(-\log(1-x)\) at \(\lambda=2\).

Comparing Transformed Distributions

A parameter choice changes more than the labels on the horizontal axis: it changes distances between observations, and it can change the balance between the positive and negative tails. Compare distributions using the same observations, transformed under stated parameter values. Useful checks include the range, center, spread, skew, and whether important observations remain separated. These summaries describe the transformed predictor; they do not establish that a fitted predictive model will perform better.

Worked Example: Comparing a Symmetric Predictor After Transformation

A hypothetical dataset contains the five predictor values \(-3,-1,0,1,3\). Transform each value using \(\lambda=0.5\), then compare the transformed mean, median, and range with those of the original values. Round summaries to four decimal places.

Method. Use the negative branch for \(-3\) and \(-1\), the positive branch for \(1\) and \(3\), and \(T_\lambda(0)=0\). Keep the parameter and dataset fixed throughout the comparison.

For \(x=-3\), the exponent is \(2-0.5=1.5\) and the base is \(1-(-3)=4\). Since \(4^{1.5}=8\), \(T_{0.5}(-3)=-(8-1)/1.5=-4.666666\ldots\).

For \(x=-1\), the base is \(2\), and \(2^{1.5}=2\sqrt{2}=2.828427\ldots\). Thus \(T_{0.5}(-1)=-(2.828427\ldots-1)/1.5=-1.218951\ldots\).

The value zero transforms to zero. For \(x=1\), \(2^{0.5}=\sqrt{2}=1.414214\ldots\), so \(T_{0.5}(1)=(1.414214\ldots-1)/0.5=0.828427\ldots\). For \(x=3\), \(4^{0.5}=2\), so \(T_{0.5}(3)=(2-1)/0.5=2\).

The transformed values in increasing order are approximately \(-4.6667,-1.2190,0,0.8284,2.0000\). Their sum, using unrounded values, is \(-4.6666667-1.2189514+0+0.8284271+2=-3.0571910\). The mean is \(-3.0571910/5=-0.6114382\), or -0.6114. The middle value is the median, 0.0000. The range is \(2-(-4.6666667)=6.6666667\), or 6.6667.

The original values have mean 0, median 0, and range \(3-(-3)=6\). The transformed median remains zero, but the mean and range change, and the negative extreme is now farther from zero than the positive extreme. The transformed values are therefore not symmetric around zero, even though the original values were.

Check and common mistake. The negative branch uses exponent \(1.5\), not \(0.5\). Applying the positive branch to negative observations would produce invalid powers in this example and would not be the Yeo-Johnson transformation.

Choosing and Applying a Parameter

The parameter \(\lambda\) is typically selected using a stated criterion rather than by assuming that one value is always best. One approach is to compare transformed distributions over candidate values of \(\lambda\). Another is to select a value under a model-based criterion, such as a likelihood that assumes the transformed predictor follows a normal distribution. Such a criterion relies on its distributional assumptions; it is not a universal guarantee of improved prediction.

When comparing candidate parameters, calculate both branches correctly and inspect the resulting values in context. A transformation can reduce an extreme tail while expanding another part of the scale. It can also change the practical interpretation of a one-unit difference in the transformed predictor. The original units should therefore remain clear when communicating results.

1
Check the domain.
Yeo-Johnson accepts positive, zero, and negative real values; no positive shift is required.
2
Identify the sign and parameter case.
Use the nonnegative branch for \(x\geq0\), the negative branch for \(x<0\), and the logarithmic formula only at its specified parameter value.
3
Compare on the same observations.
Assess how candidate values of \(\lambda\) affect the transformed distribution, and state the criterion used to choose among them.

Common Mistakes and Exam Traps

  • Using the wrong branch. The branch depends on the sign of \(x\), not on the sign of \(\lambda\). Check the input first.
  • Treating every special case as logarithmic. At \(\lambda=0\), only the nonnegative branch is logarithmic; at \(\lambda=2\), only the negative branch is logarithmic.
  • Dropping the negative sign. The negative branch has a leading minus sign. Omitting it can turn a negative input into a positive transformed value, contradicting the increasing property and \(T_\lambda(0)=0\).
  • Assuming symmetry is guaranteed. The transformation is increasing, but it does not guarantee a symmetric distribution or better predictive accuracy.
  • Confusing the parameter with the input. The negative branch uses the exponent \(2-\lambda\); it does not generally use exponent \(\lambda\).
Key takeaway: Yeo-Johnson provides a power transformation for predictors on the full real line. Correct application requires the appropriate sign-dependent branch, special handling at \(\lambda=0\) and \(\lambda=2\), and a comparison of transformed distributions that does not overstate what shape alone can establish. This treatment is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Check Your Understanding

For each problem, identify the appropriate branch before calculating. Round numerical transformed values to four decimal places where needed.

  1. For \(\lambda=0\), calculate \(T_0(2)\) and \(T_0(-2)\). Show which formula applies to each. (Answer: \(1.0986\) and \(-4.0000\), respectively.)
  2. For \(\lambda=2\), calculate \(T_2(-1)\) and \(T_2(1)\). (Answer: \(-0.6931\) and \(1.5000\), respectively.)
  3. For \(\lambda=1.5\), calculate \(T_{1.5}(3)\) and \(T_{1.5}(-3)\). (Answer: \(4.6667\) and \(-2.0000\), respectively.)
  4. For \(\lambda=0.5\), calculate \(T_{0.5}(-8)\) and \(T_{0.5}(8)\). Check that the results have the same signs as their inputs. (Answer: \(-17.3333\) and \(4.0000\), respectively.)
  5. A colleague says that \(\lambda=1\) is logarithmic because it is a special parameter value. Evaluate the transformation at \(x=-2,0,4\) and correct the claim. (Answer: \(T_1(-2)=-2,\ T_1(0)=0,\ T_1(4)=4\); \(\lambda=1\) gives the identity transformation, not a logarithmic transformation.)
Clinical Biostats