Module 4: Data Transformations

When Data Aren't Normal - Fix It!

โ˜๏ธ Working Guidelines

0% Complete

๐ŸŽฏ Learning Objectives

By the end of this module, you will:

  1. Understand WHY transformations work to normalize data
  2. Learn which transformation to use for different types of skewness
  3. Apply transformations and evaluate their effectiveness
  4. Recognize when NOT to transform (and use non-parametric tests instead)

๐Ÿ”ง The Problem

You've diagnosed non-normality. Now what?

In previous modules, you learned to detect non-normal data. But what do you actually DO about it?

Three options:

  1. Transform the data (this module!)
  2. Use non-parametric tests (Module 5)
  3. Accept the violation if n is large (Module 3)

Today, we'll explore transformationsโ€”mathematical operations that can "fix" skewed data.

Part 1: Why Do Transformations Work?

๐Ÿ’ก The Intuition

Imagine reaction times: 200ms, 400ms, 800ms, 1600ms

Original data:

After log transformation:

Result: The log transformation "pulls in" extreme values proportionally, creating symmetry!

Part 2: Types of Transformations

๐Ÿ“š Transformation Toolkit

Type of Skew Transformation Formula When to Use
Right Skew
(long tail right)
Log log(x) Reaction times, income, counts
Right Skew
(mild)
Square Root โˆšx Count data, mild skew
Left Skew
(long tail left)
Square xยฒ Proportion data near 1
Left Skew Reflect + Log log(max - x + 1) When square doesn't work

โš ๏ธ Important: Log and square root require all values > 0. If you have zeros or negatives, add a constant first!

Part 3: ๐Ÿ”ฎ Predict First

Before you run anything. In Part 4 you will take a set of right-skewed reaction times and try three transformations on them: square root, log, and reciprocal (1/y).

The reciprocal is the most aggressive of the three — it compresses large values harder than either of the others.

Predict: which will do the best job of making these data normal?




Second prediction. A classmate says: "I z-scored my reaction times, so now they're normal." Will z-scoring fix the skew? Say why or why not before you check.

Part 4: The Transformation Lab, in R

Open Posit Cloud. These are the same hist(), shapiro.test(), and skewness() tools from Chapter 11, plus Chapter 12's transformations.

4.1 — Meet the raw data

Sixty reaction times from a caffeine study. Reaction times are the textbook case for transformation: bounded below by zero, with a long tail of slow responses.

set.seed(150) rt <- data.frame( reaction_time = c(rlnorm(30, meanlog = log(330), sdlog = 0.42), rlnorm(30, meanlog = log(255), sdlog = 0.42)), condition = rep(c("Placebo", "Caffeine"), each = 30) ) hist(rt$reaction_time, col = "salmon", main = "Raw reaction times", xlab = "RT (ms)") shapiro.test(rt$reaction_time) library(e1071) skewness(rt$reaction_time)
Check your output
Shapiro-Wilk normality test data: rt$reaction_time W = 0.89749, p-value = 0.0001067 > skewness(rt$reaction_time) [1] 1.387571

Skewness 1.39 against Chapter 11's |skew| < 0.5 threshold, and Shapiro-Wilk p = .0001. These data need help.

4.2 — Try all three candidates

Chapter 12's advice is to work through the candidates and compare, not to guess once. Apply all three, then look at all four histograms together.

rt$sqrt_rt <- sqrt(rt$reaction_time) rt$log_rt <- log(rt$reaction_time) rt$recip_rt <- 1 / rt$reaction_time par(mfrow = c(2, 2)) hist(rt$reaction_time, main = "Raw", xlab = "") hist(rt$sqrt_rt, main = "Square root", xlab = "") hist(rt$log_rt, main = "Log", xlab = "") hist(rt$recip_rt, main = "Reciprocal", xlab = "") par(mfrow = c(1, 1)) shapiro.test(rt$sqrt_rt); skewness(rt$sqrt_rt) shapiro.test(rt$log_rt); skewness(rt$log_rt) shapiro.test(rt$recip_rt); skewness(rt$recip_rt)

Question 1: Record what you got. (Enter p as a decimal.)

Version Shapiro p Skewness
Raw
Square root
Log
Reciprocal
Check your output — open this after filling in the table
sqrt_rt W = 0.97052 p = 0.15468 skewness = 0.66699 log_rt W = 0.99571 p = 0.99915 skewness = -0.01928 recip_rt W = 0.89633 p = 9.691e-05 skewness = 1.35337

Log wins, and it is not close. Skewness −0.019, Shapiro-Wilk p = .999. That is what a transformation looks like when it is the right one.

Square root helped, but not enough. It clears p > .05 (p = .155), which is why it is tempting to stop there — but its skewness is 0.667, still over Chapter 11's 0.5 line. The test and the descriptive disagree, and when they do, look at the histogram.

Now the surprise: the reciprocal did essentially nothing. Skewness went from 1.388 to 1.353. The most aggressive transformation was the least effective one.

There is a clean reason. These reaction times are lognormal — that is what rlnorm() generates, and it is roughly what real reaction times look like. If Y is lognormal then 1/Y is also lognormal, just with the sign of the log-mean flipped. The reciprocal cannot fix this skew because it maps the distribution family onto itself. Strength was never the point; matching the shape is.

Question 2: Was your Part 3 prediction right? Explain why "more aggressive" turned out not to mean "more effective."

Question 3: The square root gave p = .155 (passes) but skewness 0.667 (fails Chapter 11's threshold). If you only had one of those two numbers, which would you rather have, and what would you do with a disagreement like this?

4.3 — The z-score trap

Now test your second prediction.

rt$z_rt <- scale(rt$reaction_time) skewness(rt$reaction_time) skewness(as.numeric(rt$z_rt)) shapiro.test(rt$reaction_time) shapiro.test(as.numeric(rt$z_rt))
Check your output
skewness raw = 1.3875705 skewness z-scored = 1.3875705 shapiro raw W = 0.89749 p = 0.00010672 shapiro z W = 0.89749 p = 0.00010672

Not similar. Identical — to twelve decimal places.

Z-scoring subtracts a constant and divides by a constant. That slides the distribution along the number line and changes its width. It cannot bend it. Skewness is a shape statistic and is unchanged by any linear rescaling, which is why the Shapiro-Wilk output is byte-for-byte the same.

Z-scoring is genuinely useful — for putting variables with different units on a common scale, or for comparing regression predictors. It is simply not a normality fix, and Chapter 12 lists it in the common-errors table for exactly this reason.

Question 4: Your classmate is not convinced. Using the two skewness values, write the one-sentence explanation that would actually change their mind.

4.4 — The zero trap

One recording glitch logged a reaction time of 0 ms. Watch what the log does with it.

glitch <- c(250, 310, 0, 420, 500) log(glitch) mean(log(glitch)) log(glitch + 1)
Check your output
> log(glitch) [1] 5.521461 5.736572 -Inf 6.040255 6.214608 > mean(log(glitch)) [1] -Inf > log(glitch + 1) [1] 5.525453 5.739793 0.000000 6.042633 6.216606

log(0) is -Inf, and one -Inf makes the mean of the whole variable -Inf. Every downstream statistic is then garbage, and R will not warn you — it will just quietly return -Inf or NaN.

log(y + 1) is the standard fix, and it changes the interpretation slightly: you are now modelling log(RT + 1 ms), not log(RT). Say so in the write-up. And before you reach for it, ask whether a 0 ms reaction time is real data or a recording error that should be removed.

4.5 — Run the test, and report the scale

Log won. Run the analysis on log_rt, not on the raw variable.

t.test(log_rt ~ condition, data = rt) library(effsize) cohen.d(log_rt ~ condition, data = rt)
Check your output
Welch Two Sample t-test data: log_rt by condition t = -3.1977, df = 57.368, p-value = 0.002256 95 percent confidence interval: -0.5936543 -0.1364861 sample estimates: mean in group Caffeine mean in group Placebo 5.482665 5.847735 Cohen's d d estimate: -0.8256376 (large) 95 percent confidence interval: lower upper -1.3640486 -0.2872265

4.6 — Back-transforming, so a human can read it

"The groups differ by 0.365 log-milliseconds" is true and useless. Convert it.

m <- tapply(rt$log_rt, rt$condition, mean) m d <- m[["Placebo"]] - m[["Caffeine"]] d exp(d) exp(m) # back-transformed group means
Check your output
mean log Caffeine = 5.482665 ; mean log Placebo = 5.847735 difference in logs = 0.365070 exp(difference) = 1.440615 back-transformed means: Caffeine 240.4867 Placebo 346.4488 raw arithmetic means: Caffeine 260.6829 Placebo 384.2029

On the log scale a difference becomes a ratio. exp(0.365) = 1.44, so placebo reaction times are about 44% longer than caffeine ones. That is a sentence a reader can use, and it is the honest translation of a log-scale result.

Note the back-transformed means (240.5, 346.4) are lower than the raw arithmetic means (260.7, 384.2). Back-transforming a mean log gives you the geometric mean, which for skewed data sits below the arithmetic mean. That is not an error — it is a different, and for skewed data often more representative, summary. Just do not label it as the arithmetic mean.

๐Ÿ“ Reflection Questions

Question 5: In your own words, explain WHY the log transformation works for right-skewed data. What does it do to large vs. small values?

Question 6: Write the APA-style sentence reporting this analysis. It must name the transformation, say what prompted it, give the test result, give the effect size, and state the scale. Use the back-transformed ratio to make the size human-readable.

Question 7: Your results are in log(reaction time) units. A reader asks "so how much faster was caffeine, in milliseconds?" Answer them — and explain why that question is harder than it sounds.

Part 4: When NOT to Transform

๐Ÿšซ Stop! Don't Transform These:

1. Bimodal Distributions

Two peaks = two groups. Transformation won't fix thisโ€”you need to analyze groups separately or investigate why there are two distributions.

2. Categorical/Ordinal Data

Likert scales (1-5 ratings) shouldn't be transformed. Use non-parametric tests or treat as ordinal.

3. When You're "P-Hacking"

Don't try 10 different transformations until you get p > .05 in Shapiro-Wilk! Choose based on data type, not desired outcome.

4. When Non-Parametric is Easier

If transformation makes interpretation too complex, just use Mann-Whitney or Kruskal-Wallis.

Part 5: Decision Flowchart

๐Ÿ—บ๏ธ When to Transform: Decision Guide

Step 1: Check your diagnostic plots

Step 2: Consider your data type

Step 3: Apply transformation and re-check

Step 4: Report clearly

Part 6: Practice Scenario

Scenario: You're analyzing time spent studying (in minutes) for 40 students:

Question 4A: Based on this information, what transformation would you try first? Why?

Question 4B: After applying log transformation, you get:

Write how you would report this in a Methods section:

Question 4C: Your analysis yields a mean of 4.20 on the log scale (SE = 0.15). How would you report this in original minutes?

Hint: exp(4.20) = 66.7 minutes

Part 7: Common Mistakes

โš ๏ธ Don't Make These Errors:

Mistake 1: Transforming without checking if it helped

โŒ "I log-transformed the data" (but didn't verify it worked)
โœ“ "Log transformation improved normality (W = 0.89 โ†’ 0.96, p = 0.002 โ†’ 0.22)"

Mistake 2: Trying transformations until p > .05

โŒ P-hacking: Testing 5 transformations to find one that works
โœ“ Choose based on data characteristics, not desired p-value

Mistake 3: Forgetting about zeros/negatives

โŒ log(0) = error!
โœ“ Add constant: log(x + 1) if you have zeros

Mistake 4: Not considering interpretability

โŒ Running complex analysis on transformed data without explaining results
โœ“ Back-transform key results for interpretation

Mistake 5: Transforming categorical data

โŒ log(Likert scale 1-5)
โœ“ Use non-parametric tests for ordinal data

๐ŸŽฏ Key Takeaways

What You Should Remember:

โœ“ Transformations change the scale to make data more normal

Log, square root, and square transformations can fix many skewness problems.

โœ“ Choose based on data type and skew direction

โœ“ Always verify the transformation worked

Re-check histograms, Q-Q plots, and Shapiro-Wilk after transforming.

โœ“ Report clearly and consider interpretation

Tell readers what you did and back-transform results when appropriate.

โœ“ When in doubt, use non-parametric

If transformation is too complex or doesn't help, non-parametric tests are a great alternative!

๐Ÿ“š Looking Ahead

In Module 5, you'll learn:

๐Ÿ“‹ Before You Submit

โœ… Submission Checklist

Grading: Credit/no-credit, not scored for correctness — but credit requires a genuine attempt; blank or clearly-unattempted answers earn no credit. Work through it with your partner and say what you actually think; a wrong idea you reasoned your way to is worth more here than a right one you copied.

๐Ÿ“ค How to Submit

  1. Click "Save Progress"
  2. Print: Ctrl+P (Windows) or Cmd+P (Mac)
  3. Choose "Save as PDF"
  4. Save as: module4_lastname1_lastname2.pdf
  5. Upload to your course site

๐ŸŽ‰ You've mastered data transformations! ๐ŸŽ‰

Next: Module 5 will cover non-parametric alternatives when transformation isn't the answer!