Why transform data?
A Student's t-test assumes each group is normally distributed and that the groups have equal variance (homogeneity of variance, HOV). When a dataset is badly skewed, one option is to transform it: apply the same mathematical function to every value so the data are rescaled into a more symmetric shape.
- Linear transformations (add, subtract, multiply or divide by a constant) move or stretch the data but keep its shape. They never fix skew.
- Non-linear transformations (log, square root, exponential) change the spacing between values, which is what changes the shape.
- After analysing transformed data, you back-transform results (means, confidence limits) into the original units so they make sense.
See it: what each transformation does to skewed data
These are C-reactive protein (CRP) levels from 400 adults at a large health screening (simulated data). Most people have low CRP and a few have very high values, so the histogram has a long tail to the right: the data are right-skewed. Choose a transformation and watch the bars reshape. The dashed line shows what a normal distribution with the same mean and SD would look like. (In the lab you'll work by hand with a smaller group of 12 patients.)
Linear: changes the numbers, not the shape
- Multiply by 2
- Every value × 2. A CRP of 3.0 becomes 6.0. Like changing units (e.g. mg/L to mg/dL is ÷ 10).
- Add 5
- Every value + 5. A CRP of 3.0 becomes 8.0. The whole dataset slides along the axis.
Non-linear: changes the spacing, so the shape changes
- √x
- Square root. 4 becomes 2, 9 becomes 3, 16 becomes 4.
- log₁₀(x)
- The power of 10. 10 becomes 1, 100 becomes 2.
- ln(x)
- The power of e. 2.72 becomes 1, 7.39 becomes 2.
- 1 / x
- The inverse. 2 becomes 0.5, 4 becomes 0.25. Big values become small and small values become big.
Which transformation for which problem?
| Problem in the data | Try | Back-transform with | Excel |
|---|---|---|---|
| Right skew (long tail of large values) | ln(x) or log₁₀(x) | eˣ or 10ˣ | =LN() → =EXP()=LOG10() → =10^ |
| Mild right skew, counts | √x | x² | =SQRT() → =^2 |
| Severe right skew | 1 / x | 1 / x | =1/A2 |
| Left skew (long tail of small values) | x² or eˣ | √x or ln(x) | =A2^2, =EXP() |
| Proportions (0 to 1) | logit | inverse logit | covered later |
Every transformation has an opposite (inverse) that undoes it. ln and eˣ are a pair: eln(x) = x. That is the whole idea behind back-transformation.
How to use the calculator
There is nothing to calculate on this page. You'll use the calculator in the eˣ, log₁₀ and ln tabs and in the back-transform lab. It sits beside the lesson (on a phone, tap the Calculator button). Read these tips now, or come back to them any time.
1 · Press the function first
Pressing ln types ln(. Then type your number. The bracket closes itself when you press =.
2 · Watch the top line
The grey line shows exactly what is being calculated, like e^(1.5). If it doesn't match what you meant, press C and start again.
3 · Send the answer
Click an answer box first, then press Use this value to drop the result in, rounded to 4 decimal places.
4 · Stuck? Press "Show me"
Every question has a Show me button that presses the keys on the calculator for you, one at a time.
An exponential transformation raises a base to the power of each data value. In biology the base is almost always Euler's number, e ≈ 2.718. So for the value 2, the transformed value is e² = 2.718 × 2.718 = 7.389.
Exponentials stretch out large values: each step of 0.5 in x makes y jump by more than the step before. That is why eˣ can pull a left-skewed dataset toward symmetry, and why it is the tool for undoing a natural log.
=EXP(0.5)
Result1.6487
Calculate eˣ for x = 1, 1.5, 2 and 2.5, then see them on the graph
Reading the graph: every point is (x, y). x is how far across; y is how high up.
- x is your starting value (1, 2, 3…). It never changes.
- ◇ Before: each starting value is plotted at (x, x), so its height is the same number as its x. For x = 2, the diamond is at (2, 2). These diamonds sit on the dotted line y = x.
- ● After: when you type your answer, a dot appears at (x, your answer), so for x = 2 the dot goes at (2, e²). Same x, new height.
- The arrow shows how the transformation changed the value: straight up or down, because only y changes.
Round every answer to 4 decimal places, for example 1.6487. The calculator shows the rounded value under each result, and Use this value rounds it for you.
Same x, new y: a transformation changes the value (the height on this graph), never the x.
Same shape, different base. 2ˣ passes through (2, 4), eˣ through (2, 7.39) and 10ˣ through (2, 100, off the top of the graph). The base you use matters, so always check you are using e.
- Try e0. What do you get, and why does every exponential curve pass through (0, 1)?
- x goes up by 0.5 each time. Does y go up by the same amount each time, or do the gaps grow?
- Look at the arrows. Did eˣ move the starting values up or down? Which value moved the most?
- Tick "Compare with 2ˣ and 10ˣ". Which base grows fastest?
- Take one of your answers and press ln on it. What do you get back?
A logarithm answers one question: "What power do I raise the base to, to get this number?" For base 10, log₁₀(1000) = 3 because 10³ = 1000.
Logs compress large values: 1,000 becomes 3, and 10,000 only becomes 4. That is why logs pull in the long tail of right-skewed data.
- log of 1 is 0 for any base, because anything raised to the power 0 is 1.
- log of 0 or a negative number is undefined. Try it on the calculator and see what happens.
| Number | written as a power of 10 | log₁₀(number) |
|---|---|---|
| 1 | 10⁰ | 0 |
| 10 | 10¹ | 1 |
| 100 | 10² | 2 |
| 1,000 | 10³ | 3 |
| 10,000 | 10⁴ | 4 |
=LOG10(20)
Result1.3010
Calculate log₁₀(x) for x = 1 to 5, then see them on the graph
Reading the graph: every point is (x, y). x is how far across; y is how high up.
- x is your starting value (1, 2, 3…). It never changes.
- ◇ Before: each starting value is plotted at (x, x), so its height is the same number as its x. For x = 2, the diamond is at (2, 2). These diamonds sit on the dotted line y = x.
- ● After: when you type your answer, a dot appears at (x, your answer), so for x = 2 the dot goes at (2, log₁₀(2)). Same x, new height.
- The arrow shows how the transformation changed the value: straight up or down, because only y changes.
Round every answer to 4 decimal places, for example 1.3010 (keep the final zero). The calculator shows the rounded value under each result, and Use this value rounds it for you.
Same x, new y: a transformation changes the value (the height on this graph), never the x.
- Try log of 10, 100 and 1000. What pattern do you see?
- Try log of 0, then log of a negative number. What does the calculator say, and why?
- Going from x = 1 to 2 adds 0.30 to y. How much does going from x = 4 to 5 add?
- Look at the arrows. Which starting value moved furthest from the y = x line?
The natural log, written ln (or logₑ), asks: "What power do I raise e to, to get this number?" ln(7.389) = 2 because e² = 7.389.
It is the most common log transformation in biology, and it pairs with eˣ (Excel EXP) for back-transforming. ln gives bigger numbers than log₁₀ for the same x, but the shape is the same: ln(x) is always 2.303 × log₁₀(x).
=LN(20) then =EXP(2.9957)
Calculate ln(x) for x = 1 to 5, then see them on the graph
Reading the graph: every point is (x, y). x is how far across; y is how high up.
- x is your starting value (1, 2, 3…). It never changes.
- ◇ Before: each starting value is plotted at (x, x), so its height is the same number as its x. For x = 2, the diamond is at (2, 2). These diamonds sit on the dotted line y = x.
- ● After: when you type your answer, a dot appears at (x, your answer), so for x = 2 the dot goes at (2, ln(2)). Same x, new height.
- The arrow shows how the transformation changed the value: straight up or down, because only y changes.
Round every answer to 4 decimal places, for example 2.9957. The calculator shows the rounded value under each result, and Use this value rounds it for you.
Same x, new y: a transformation changes the value (the height on this graph), never the x.
- Try ln(e): press ln, then the e key. Why is the answer exactly 1?
- Compare ln(5) with log₁₀(5). Which is bigger, and why? (Hint: which base is smaller, e or 10?)
- Tick "Compare with log₁₀(x)". Do the two curves have the same shape?
- Pick any answer and press eˣ on it. Do you get your starting value back?
C-reactive protein at a health screening
C-reactive protein (CRP) is made by the liver and rises in the blood when there is inflammation in the body. A clinic measured CRP (in mg/L) in 12 adults at a routine screening. Doctors often group results like this: below 1 mg/L lower risk, 1 to 3 average, above 3 higher cardiovascular risk.
Most people have low CRP, but a few have high values. Your job: decide what a typical CRP is for this group.
Example data made up for practice, with values in a realistic range.
Look at the raw data: is CRP normally distributed?
mg/LEach dot is one patient, stacked in 2 mg/L bins like a histogram. Most patients pile up on the left, and two high patients (9.8 and 18.5) sit far out to the right. The arithmetic mean (4.22) is bigger than 9 of the 12 values.
Show the arithmetic mean calculation
Shapiro-Wilk test
This test checks whether data look like they came from a normal distribution.
- p < 0.05: not normal. The assumption fails.
- p ≥ 0.05: no evidence against normality. The assumption is OK.
Transform: calculate ln(CRP) for every patient
log scale=LN(B2), then fill down
Steps 2 to 5: round every answer to 4 decimal places, for example 1.4351. Keep the minus sign on negative values, like −0.9163.
Values below 1 give a negative ln. That is fine: ln(0.4) = −0.9163 because e−0.9163 = 0.4. Only 0 and negative raw values can't be logged.
Before and after the transformation
Dotted circles fill in as you calculate each patient.
Find the mean on the log scale
log scaleAdd up all 12 ln values and divide by 12. This number is in "ln mg/L" units, which nobody can picture, so don't stop here.
Excel: =AVERAGE(C2:C13)
Back-transform: turn the log-scale mean into mg/L
back to mg/LYou transformed with ln, so you undo it with eˣ: raise e to the power of your log-scale mean. The answer is called the geometric mean.
=EXP(D2)
Why is the geometric mean smaller than the arithmetic mean?
Press Play to watch the back-transformation happen, or use Back and Next to go one stage at a time.
- Start with the 12 ln(CRP) values from Step 2, on the log scale.
- Average them on the log scale: mean = 0.857 (Step 3).
- eˣ carries each patient back down to mg/L. Watch the lines fan out: eˣ stretches the high values far apart.
- eˣ of the log-scale mean lands at 2.36 mg/L. That is the geometric mean (Step 4).
- The ordinary average of the mg/L values is 4.22, higher than 9 of the 12 patients. The geometric mean (2.36) sits in the middle of the group: 6 patients below it and 6 above.
- Why the difference? Every value pulls on its mean, on both scales. On the log scale (top) the extremes balance: the lowest patient is 1.77 below the mean and the highest is 2.06 above. In mg/L (bottom) they don't: the highest patient (circled, 18.5) is 14.3 above the arithmetic mean, but the lowest is only 3.8 below. The far-out high values drag the arithmetic mean up much more.
Try it: change one patient
These are the 12 patients from this lab. Drag the slider to change patient 12 (now 18.5 mg/L) and watch what happens to each mean.
Key idea: back-transforming the mean of the logs does not give back the ordinary mean. It gives the geometric mean, a typical value that a few very high patients can't drag upward nearly as much.
For the curious: another way to get the geometric mean
Confidence interval: calculate on the log scale, then back-transform the limits
ln → mg/LThe mean, SD, SE and both limits all come from the ln(CRP) values. Never use the raw mg/L numbers here.
Turn the two finished limits back into mg/L with eˣ.
Formula reminders
Use these numbers. They all come from the ln(CRP) column you made in Step 2.
=STDEV.S(C2:C13)Not these: the raw mean (4.2167) and raw SD (5.2457) describe the skewed mg/L data. Using them gives the wrong interval.
Why is the interval lopsided in mg/L?
Press Play to watch the interval get built on the log scale and then back-transformed.
- On the log scale: the 12 ln(CRP) values and their mean, 0.857.
- Build the 95% CI on the log scale: 0.857 ± 2.201 × 0.3235 = 0.857 ± 0.71. Same distance on both sides.
- Back-transform the two limits with eˣ: e0.145 = 1.16 and e1.569 = 4.80 mg/L. The mean comes down too: e0.857 = 2.36.
- In mg/L the interval is lopsided: 1.20 below the geometric mean but 2.45 above. eˣ stretches the upper side more, and the lower limit can never go below 0.
eSE = e0.3235 = 1.38, but that number has no meaning in mg/L. Building a CI as "mean ± t* × 1.38" gives the wrong interval. Always finish the CI on the ln scale first, then back-transform only the two limits.
- Compare both means with the risk groups (below 1, 1 to 3, above 3 mg/L). Which group does each one put a "typical" patient in? Which mean describes this group better?
- In "Try it: change one patient", drag patient 12 all the way up, then all the way down. Which mean changes more, and why?
- Calculate e0.3235 (the SE back-transformed). Why doesn't that number make sense in mg/L?
- Look at the interval diagram. Why does the interval stretch further above the geometric mean than below it?