Answer
Log-transforming data: when it helps, and what it changes
The short answer
Use a log when your numbers are positive, right-skewed and vary by factors rather than fixed amounts, as prices, incomes, concentrations and reaction times often do. On the log scale, equal ratios become equal distances, skew shrinks, and spread stops growing with the level. Nothing is lost, because exp() undoes the log, but results now describe geometric means and ratios rather than arithmetic means and differences.
Why a log helps: many quantities grow by factors
A logarithm turns multiplication into addition: log(a × b) = log(a) + log(b). That matters because many real quantities change in proportion to their size. A stock that moves 2% a day moves more dollars at $500 than at $5; a salary raise, a bacterial count or a drug concentration also tends to change by a percentage. When data are built from many such proportional nudges, they pile up near zero with a long right tail, and the log of the values tends to look roughly normal. That shape is called log-normal.
On the log scale, a doubling is the same distance whether it goes from 10 to 20 or from 1,000 to 2,000. That single change brings several practical benefits:
- Skew shrinks. A handful of huge values no longer dominate the mean, the standard deviation or a regression fit.
- Spread steadies. When variability grows with the level (big firms vary more in dollars than small ones), logs often make the spread similar across groups, which helps t tests, ANOVA and regression.
- Effects become proportional. A difference on the log scale is a ratio on the original scale, which is often the question people actually care about: is one group 30% higher than the other?
- Plots become readable. Values spanning several orders of magnitude can be seen on one axis instead of being squashed into a corner.
When to use a log, and when not to
Good signs: every value is strictly positive, the data are right-skewed, the largest values are many times the smallest, the spread rises with the mean, and it makes sense to talk about changes in percent. Subject-matter knowledge counts more than any test. If the process is multiplicative, a log scale is the natural one even when a histogram is ambiguous.
- Zeros or negatives. log(0) is undefined. Adding an arbitrary constant such as 1 changes the results depending on the constant you pick, so consider a model built for the data instead, such as Poisson or negative binomial regression for counts, or a two-part model when zeros are common.
- Data that are already symmetric, or bounded on both sides, such as proportions or rating scales. A log can create left skew rather than fix anything.
- When the arithmetic mean is the target. Total cost, total rainfall and total revenue are sums, so a budget question needs the ordinary mean, not a geometric one. A generalized linear model with a log link can model ratios while still targeting the mean.
- Only to pass a normality test. Check a QQ plot and think about the scale of the question rather than chasing a p-value.
Is the transformation lossless?
For positive numbers, yes: each value has exactly one log, and exp() returns the original. Orderings, medians and percentiles carry straight back, so the median of the logged data, exponentiated, is the median of the original data.
Means do not carry back the same way. The average of the logs, exponentiated, is the geometric mean, which for right-skewed data sits below the ordinary mean and close to the median. A difference in mean logs becomes a ratio of geometric means, and a confidence interval on the log scale becomes an interval for that ratio. Standard deviations and regression slopes on the log scale are likewise about multiplicative spread and percent change. So the conclusions are valid, but they answer a slightly different question, and your write-up should say which one.
See it in R and Python
The example simulates weekly spending for two groups of 150 people from log-normal distributions. It compares skewness before and after logging, shows the three candidate centres of one group, and runs a Welch t test on the log scale, back-transformed into a ratio of geometric means. The R version uses base R; the Python tab uses NumPy and SciPy.
R
set.seed(18)
n <- 150
# Right-skewed, positive data: e.g. weekly spending in dollars for two groups
a <- rlnorm(n, meanlog = log(40), sdlog = 0.8)
b <- rlnorm(n, meanlog = log(55), sdlog = 0.8)
skew <- function(x) mean((x - mean(x))^3) / sd(x)^3
round(c(raw = skew(a), logged = skew(log(a))), 2)
# Three "centres" of group A: the log scale targets the geometric mean
round(c(mean = mean(a), median = median(a), geo_mean = exp(mean(log(a)))), 2)
# Welch t test on the log scale, back-transformed to a ratio of geometric means
tt <- t.test(log(b), log(a))
ratio <- exp(unname(tt$estimate[1] - tt$estimate[2]))
round(c(ratio = ratio, lower = exp(tt$conf.int[1]), upper = exp(tt$conf.int[2])), 2)
round(c(t = unname(tt$statistic), df = unname(tt$parameter)), 2)
signif(tt$p.value, 3)
# The same comparison on the raw scale, for contrast
signif(t.test(b, a)$p.value, 3)
# The transform loses nothing for positive numbers: exp() undoes it
all.equal(exp(log(a)), a)Python
import numpy as np
from scipy import stats
rng = np.random.default_rng(18)
n = 150
# Right-skewed, positive data: e.g. weekly spending in dollars for two groups
a = rng.lognormal(mean=np.log(40), sigma=0.8, size=n)
b = rng.lognormal(mean=np.log(55), sigma=0.8, size=n)
def skew(x):
return np.mean((x - x.mean()) ** 3) / x.std(ddof=1) ** 3
print("skewness raw", round(skew(a), 2), "logged", round(skew(np.log(a)), 2))
# Three "centres" of group A: the log scale targets the geometric mean
print("mean", round(a.mean(), 2), "median", round(np.median(a), 2),
"geo_mean", round(np.exp(np.log(a).mean()), 2))
# Welch t test on the log scale, back-transformed to a ratio of geometric means
la, lb = np.log(a), np.log(b)
diff = lb.mean() - la.mean()
va, vb = la.var(ddof=1) / n, lb.var(ddof=1) / n
se = np.sqrt(va + vb)
df = (va + vb) ** 2 / (va ** 2 / (n - 1) + vb ** 2 / (n - 1))
tcrit = stats.t.ppf(0.975, df)
res = stats.ttest_ind(lb, la, equal_var=False)
print("ratio", round(np.exp(diff), 2), "lower", round(np.exp(diff - tcrit * se), 2),
"upper", round(np.exp(diff + tcrit * se), 2))
print("t", round(res.statistic, 2), "df", round(df, 2), "p", float(f"{res.pvalue:.3g}"))
# The same comparison on the raw scale, for contrast
print("raw-scale p", float(f"{stats.ttest_ind(b, a, equal_var=False).pvalue:.3g}"))
# The transform loses nothing for positive numbers: exp() undoes it
print(np.allclose(np.exp(np.log(a)), a))The figures below come from one seeded run of the R code. Python uses a different random number generator, so its figures differ slightly, but they show the same pattern.
- Skew disappears. The skewness of group A is 2.62 on the raw scale and -0.03 after logging.
- The centres split apart. Group A's ordinary mean is 51.34 dollars, pulled up by a few big spenders, while its median is 41.15 and its geometric mean 37.56. The true median and geometric mean in the simulation are both 40.
- The effect reads as a ratio. Group B's geometric mean is 1.36 times group A's, 95% CI [1.13, 1.64], Welch t(297.39) = 3.26, p = 0.00126. The simulated true ratio is 55/40 = 1.375.
- Both scales agree here. The raw-scale Welch test gives p = 0.00335. The log-scale version answers a proportional question and is less swayed by the few largest values.
- Nothing was lost. Exponentiating the logs returns the original values exactly (all.equal is TRUE).
How to report a ratio of geometric means in APA style (7th edition)
State in the method section that the variable was log-transformed and why, then report results back-transformed to the original units so readers never have to think in logs. Using the example above:
"Because weekly spending was strongly right-skewed, it was natural-log transformed before analysis, and results are back-transformed to ratios of geometric means. Group B's geometric mean spending was 1.36 times that of Group A, 95% CI [1.13, 1.64], Welch's t(297.39) = 3.26, p = .001."
In descriptive tables, give the geometric mean with its back-transformed confidence interval (or the median with the interquartile range) rather than the mean and SD of the logs, and add a table note saying which transformation was used.
Related tools and guides
- t-test power and sample size calculator
- APA 7 formatter for t tests
- APA 7 formatter for descriptive statistics
- Which statistical test should I use?
- How to interpret a QQ plot
- Is a normality test worth running on your data?
- Log-normal distribution (Wikipedia)
More answered questions
- What does kurtosis actually tell you about your data?
- What do p values and t values actually mean?
- What are degrees of freedom in statistics, really?
Working with your own data?
General answers only go so far. Send us your situation and we'll reply by email within two business days.
Ask your questionWritten by AskStats with AI assistance. This is general information, not advice for your specific data or study. When the results matter, check your approach with a qualified statistician.