12  Data Transformations

NoteWhat you’ll be able to do

By the end of this chapter you will be able to:

  1. Explain what a transformation does, and when to prefer one over a non-parametric test.
  2. Choose an appropriate transformation (log, square root, reciprocal) for a given skew.
  3. Apply a transformation in R and re-check normality afterward.
  4. Interpret and report results on the transformed scale — without overclaiming about the original units.

When your data (or your model’s residuals) are clearly non-normal and you want to keep using a parametric test, there are two options. This chapter is about the first one: transforming the data into a more normal-looking form. The next chapter covers the second: switching to a non-parametric test.

A transformation is a deterministic function applied to every value in a variable. The most common transformations — log, square root, reciprocal — re-scale right-skewed data so that the long tail is pulled in and the distribution becomes more symmetric.

12.1 What transformations are for

Transformations serve three related purposes:

  1. Improve approximate normality so that the assumptions of t-tests, ANOVA, and regression are better met.
  2. Stabilize variance. Many datasets show variance that grows with the mean (heteroscedasticity); the right transformation can flatten that.
  3. Make relationships more linear. A log transformation can turn a curved scatterplot into a straight line, which is what linear regression needs.

The cost — and you should be clear about this — is that conclusions then apply to the transformed scale. Saying “log income differs between groups” is a true claim, but it is not exactly the same claim as “income differs between groups.”

12.2 When to use transformations vs. non-parametric tests

Both options exist for the same reason: your data don’t meet a parametric test’s assumptions. They give you different trade-offs.

12.2.1 Use a transformation when

  • The deviation from normality is moderate, and you suspect a single transformation (log, sqrt) could fix it.
  • You want to keep the interpretability of the parametric framework (slopes, effect sizes, confidence intervals).
  • You’re comfortable interpreting effects on the transformed scale (and reporting them that way).

12.2.2 Use a non-parametric test when

  • The data are heavily skewed, have severe outliers, or stay non-normal even after transformation.
  • You’re working with ordinal data, ranks, or non-continuous variables to begin with.
  • Sample size is small and transformations aren’t doing enough.
  • You don’t want the interpretive complications of a transformed scale.

The quick correspondence:

Parametric test Non-parametric alternative
Independent t-test Mann-Whitney U (a.k.a. Wilcoxon rank-sum)
Paired t-test Wilcoxon signed-rank test
One-way ANOVA Kruskal-Wallis test
Pearson correlation Spearman’s rank correlation

Non-parametrics are covered in detail in Chapter 13. For the rest of this chapter, we’ll focus on transformations.

12.3 Common transformations

Three transformations cover the vast majority of normality problems. A fourth, z-scoring, is included because it’s often mistaken for one — it changes the numbers but not the shape.

Transformation Formula When to use it
Log \(y' = \log(y)\) Right-skewed data with positive values only
Square root \(y' = \sqrt{y}\) Moderately skewed positive data; count data
Reciprocal \(y' = 1/y\) Highly skewed data; not usable if any value is zero
Z-score \(y' = (y - \mu)/\sigma\) Standardizing data (mean 0, SD 1) — does not change shape

12.3.1 1. Log transformation

Formula: \(y' = \log(y)\)

When to use it: Right-skewed data — values bunched near the low end with a long tail to the right.

Effect: Compresses large values, spreads out small ones. After a log transformation, multiplicative relationships become additive.

Typical applications: Income, reaction times, gene expression levels, anything bounded at zero with a long upper tail.

R syntax:

data$log_y <- log(data$y)         # natural log (base e)
data$log10_y <- log10(data$y)     # log base 10 — sometimes easier to interpret

Caveat: Cannot be applied directly to zero or negative values. First ask whether the zeros are real. A real zero (a count of zero, zero income) can stay: add a small constant — log(y + 1) — or use a different transformation. Adding 1 is a pragmatic fix but changes the interpretation slightly. An impossible zero (a 0 ms reaction time from a recording glitch) is a data error: set it to NA (Chapter 7) rather than transforming it.

12.3.2 2. Square root transformation

Formula: \(y' = \sqrt{y}\)

When to use it: Moderate positive skew, especially for count data (number of events, number of correct responses, number of citations).

Effect: Reduces skew while staying more interpretable than a log. The transformation is “milder” than a log — it compresses large values less aggressively.

R syntax:

data$sqrt_y <- sqrt(data$y)

Caveat: Cannot be applied to negative values. Zero is fine (\(\sqrt{0} = 0\)).

12.3.3 3. Reciprocal transformation

Formula: \(y' = 1/y\)

When to use it: Severe positive skew when neither log nor square root is enough.

Effect: Compresses large values aggressively. The order of observations is reversed — the largest raw value becomes the smallest transformed value — so the direction of effects flips. The usual fix is to use \(-1/y\) instead: same shape, original order.

R syntax:

data$reciprocal_y <- 1 / data$y      # reverses the order
data$neg_recip_y  <- -1 / data$y     # same shape, keeps the order

Caveat: Cannot be applied if any value is zero. Use only when you have all positive (or all negative) values.

12.3.4 4. Z-score standardization

Formula: \(y' = (y - \mu)/\sigma\)

When to use it: When you want to put a variable on a standard scale (mean 0, SD 1) — useful for comparing variables on different units or for regression with predictors on very different scales.

Effect: Re-centers and re-scales the variable. Does not change the shape of the distribution. A right-skewed variable, standardized, is still right-skewed. Z-scoring is not a normality fix.

R syntax:

data$z_y <- scale(data$y)

scale() defaults to centering (subtracting the mean) and scaling (dividing by the SD).

12.3.5 Other transformations to know

  • Box-Cox transformation — a family that includes log and square root as special cases. The boxcox() function in the MASS package estimates the optimal exponent (\(\lambda\)) for your data. Useful when you don’t know which transformation will work best.
  • Squared transformation (\(y' = y^2\)) — for left-skewed data (rare in behavioral research, but it happens). Compresses small values and spreads out large ones.

12.4 How to choose and apply a transformation

  1. Look at the histogram and Q-Q plot of your variable (or residuals).
  2. Identify the type of skew.
    • Right skew (long right tail) → try log first, then square root, then reciprocal.
    • Left skew (long left tail) → try squared transformation, or reflect-and-transform.
    • Heavy tails (kurtosis problem) → transformations are less effective; consider non-parametrics.
  3. Apply the transformation.
  4. Re-check the histogram and Q-Q plot. Did it help?
  5. If yes, use the transformed variable for the analysis. If no, try the next transformation or switch to non-parametric.
# Right skew — work through the standard candidates
data$log_y <- log(data$y)
data$sqrt_y <- sqrt(data$y)

# Quick comparison
par(mfrow = c(1, 3))
hist(data$y, main = "Raw")
hist(data$sqrt_y, main = "Square root")
hist(data$log_y, main = "Log")
par(mfrow = c(1, 1))

Pick the transformation whose histogram looks most symmetric, then re-run the Shapiro-Wilk or Q-Q check on that version.

12.5 A worked example: reaction times

Reaction times are the textbook case for log transformation.

library(effsize)

# Example data: 30 reaction times per condition (simulated, right-skewed)
set.seed(12)
rt <- data.frame(condition = rep(c("caffeine", "placebo"), each = 30),
                 reaction_time = round(c(rlnorm(30, log(310), 0.4),
                                         rlnorm(30, log(370), 0.4))))

# Raw reaction times — check each condition separately
tapply(rt$reaction_time, rt$condition, shapiro.test)   # p = .002 and < .001

# Log transformation
rt$log_rt <- log(rt$reaction_time)

# Recheck, again per condition
tapply(rt$log_rt, rt$condition, shapiro.test)          # p = .773 and .245

# Run the test on the transformed variable, with an effect size
t.test(log_rt ~ condition, data = rt)
cohen.d(log_rt ~ condition, data = rt)

# Back-transform the group means (these are geometric means)
exp(tapply(rt$log_rt, rt$condition, mean))

Two histograms side by side. Left: right-skewed distribution of raw reaction times in milliseconds with a long right tail. Right: the log-transformed values forming an approximately symmetric bell shape.

What the transformation does. Left: raw reaction times are right-skewed — most values bunch at the low end with a long tail of slow responses. Right: after taking the log, the same 300 observations form a roughly symmetric distribution suitable for a parametric test.

When reporting, be explicit:

Reaction times were log-transformed prior to analysis due to right skew in both conditions (raw RT Shapiro-Wilk \(p = .002\) and \(p < .001\); log RT \(p = .773\) and \(p = .245\)). An independent-samples t-test on log reaction times showed… [continue with results on the log scale].

12.6 Interpreting effects on the transformed scale

This is the part students most often skip and then get wrong.

  • Log scale. A difference in log values reflects a multiplicative difference on the raw scale. If log income differs by 0.5 between two groups, that’s a factor of \(e^{0.5} \approx 1.65\) — group 2’s geometric mean income is about 65% higher than group 1’s. Back-transforming a mean of logs with exp() gives the geometric mean, not the ordinary mean; for right-skewed data it is smaller than the ordinary mean, so label it as a geometric mean when you report it.
  • Square root scale. Differences in \(\sqrt{y}\) don’t have a clean multiplicative or additive interpretation on the raw scale. Often the easiest move is to report both scales side by side: the means on the raw scale (for the reader’s intuition) and the test result on the transformed scale (for the statistics).
  • Reciprocal scale. Direction flips. A “positive effect” on \(1/y\) means a decrease in \(y\). Be careful when writing up.
  • Z-score scale. A unit difference on the z-scale = a one-SD difference on the raw scale. This is usually easy to translate back.

12.7 Common errors

Mistake Consequence Fix
Log-transforming data with zeros log(0) = -Inf, breaks the analysis Use log(y + 1) or pick a different transformation
Square-rooting negative values Returns NaN Reflect (multiply by -1), shift, or use a different transformation
Reporting effects on the raw scale after transforming Interpretation is wrong Either back-transform the effects, or be explicit that results are on the log/sqrt scale
Z-scoring to fix non-normality Doesn’t fix it — shape is preserved Use log or square root for normality; z-score for standardization
Stacking transformations Hard to interpret Stick to a single transformation per variable

12.8 When transformations aren’t enough

Sometimes no transformation produces approximately normal residuals. Common situations:

  • Bimodal distributions. A transformation won’t make two peaks into one.
  • Floor or ceiling effects. Data piled up at one extreme (lots of zeros, lots of 100s) don’t transform into normal.
  • Heavy-tailed distributions. Cauchy-like data resist transformation.

In those cases, go non-parametric (next chapter), or — if you have a good reason — fit a model that doesn’t assume normality (logistic regression for binary outcomes, Poisson regression for counts, robust regression for outlier-heavy data). Those alternative models are beyond the scope of this book but worth knowing exist.

12.9 Reporting transformations

Whenever you transform, the write-up should include:

  1. What transformation you applied.
  2. Why — what diagnostic prompted it.
  3. The scale on which the analysis was run.
  4. The results in their natural form for the test, and optionally back-transformed values for interpretation.

Example:

Reaction times were right-skewed in both conditions (Shapiro-Wilk \(p = .002\) for caffeine, \(p < .001\) for placebo) and were log-transformed prior to analysis. A Welch’s t-test on log reaction times indicated that the caffeine group responded faster than the placebo group, \(t(57.99) = -2.41\), \(p = .019\), \(d = -0.62\), 95% CI \([-1.15, -0.09]\). Geometric mean reaction times were 292 ms (caffeine) and 364 ms (placebo).

Every number in that paragraph comes from the worked-example code above: the fractional df is the Welch signature, d is on the log scale, and the back-transformed means are labeled as geometric means.

Onward to the alternative: when no transformation works, non-parametrics are waiting.


TipChapter Summary

Core idea: A transformation re-scales every value with the same deterministic function so that skewed data (or residuals) better satisfy normality — letting you keep a parametric test. The analysis then lives on the transformed scale, and the write-up must say so.

You should understand:

  • Which transformation suits which shape: log and square root for right skew, reflection first for left skew
  • Why effects on a log scale are multiplicative on the raw scale
  • When transformation is the wrong tool: bimodality, floor/ceiling effects, z-scoring to “fix” shape

You should be able to do in R:

  • Apply: data$log_y <- log(data$y) (use log(y + 1) if real zeros are present; set impossible zeros to NA)
  • Re-check: hist() and shapiro.test() on the transformed variable
  • Run the test on the transformed variable and report the scale explicitly

Plain-language check: A classmate says “I z-scored my reaction times so now they’re normal.” What’s wrong with that sentence?

The one mistake to avoid: Reporting effects in raw units after testing on a transformed scale. Either back-transform (and say so) or keep the interpretation on the analysis scale.

Practice: Reaction times are right-skewed with a few values of 0 ms due to a recording glitch. Which transformation do you reach for, what do you do about the zeros, and what do you check afterward?

Key terms from this chapter are defined in the Glossary.

NoteData Transformations Practice

Practice the skills from this chapter using real data: Data Transformations Practice: River Lengths.

TipWork through it with a partner

Module 4: Data Transformations applies log, square-root and reciprocal transformations to skewed data and re-checks normality after each one — including a case where no transformation helps and the honest move is to stop. It also shows why z-scoring is not a transformation in this sense: it changes the numbers without touching the shape.

Worked in R alongside the page, in pairs, printed to PDF to hand in.

This module opens in a new tab.