Lesson 8: Nonlinear Models — Transforming Data
Not every relationship is a straight line, and forcing a line onto curved data is one of the commonest mistakes in data analysis. Many real relationships are curved in recognizable ways: growth that multiplies by a constant factor, decay that shrinks by a constant proportion, or a power relationship where one variable grows as a power of another. The strategy for such data is not to abandon the line but to transform the data — to apply a function such as a logarithm or a square root to one of the variables — so that the transformed data do follow a line, and then to fit the line to the transformed values.
The logarithm is the most useful transformation because it turns multiplication into addition. If a response grows by a constant percentage each year, then the logarithm of the response grows by a constant amount, so a plot of log(y) against x is straight. This is why exponential growth, from populations to investments, is usually analysed on a log scale. Similarly, if y is a power of x, say y = a × x^b, then taking logs of both variables gives log(y) = log(a) + b × log(x), which is a straight line in log-log coordinates with slope b. The transformation reveals the structure that the raw scatterplot hides.
Choosing a transformation is guided by the residual plot and by the shape of the data, not by guesswork. If the scatterplot curves upward ever more steeply, try taking the log of the response; if it flattens out, try taking the log of the explanatory variable or the square root of the response; if it follows a power pattern, try logs of both. After each attempt, check the residual plot of the transformed model: the right transformation produces a random scatter, while the wrong one leaves a curve. There is no penalty for trying more than one, as long as you report the one you chose and why.
A transformed model needs careful interpretation, because its predictions live on the transformed scale. If you fit a line to log(y) and then want a prediction for y itself, you must undo the logarithm by exponentiating — and the result is a prediction for the median of y rather than its mean, a subtlety worth stating if it matters for your answer. Also be honest about the limits: a transformation can straighten a relationship within the observed range, but it does not license extrapolation beyond it, and a model that fits well can still be wrong about causes. In your answers, name the transformation, show the fitted model on the transformed scale, and interpret the slope on that scale.
A worked example
Worked example: consider the worked-example counts of bacteria in a culture, measured each hour as 100, 200, 400, 800, 1600, 3200. The raw scatterplot curves upward steeply, and a line fitted to it leaves a curved residual plot. Taking log base 10 of the counts gives 2, 2.30, 2.60, 2.90, 3.20, 3.51, and plotting these against hour gives points falling almost exactly on a straight line with slope about 0.30. That slope means the count multiplies by about 10^0.30, or about 2, every hour — the population doubles hourly. The transformation turned an exponential story into a linear one that a line can describe.
Transformations are a standard part of the statistician's toolkit, and free-response questions reward students who recognize when they are needed. The clue is usually a curved scatterplot or a curved residual plot, and the expected response is to propose a transformation, explain what it would do, and describe how you would check whether it worked. You are not expected to memorize a catalogue of transformations, only to understand the logic: change the scale so that the pattern becomes linear, fit the line, and interpret the result on the scale you used.
Key Terms
- Transformation
- Applying a function such as a logarithm to a variable so a curved relationship becomes linear.
- Logarithm
- The inverse of exponentiation; log(y) grows by a constant amount when y grows by a constant factor.
- Exponential growth
- Growth by a constant multiplier per unit of time; linear on a log scale.
- Power model
- A relationship of the form y = a × x^b, which becomes linear when both variables are logged.
- Back-transformation
- Undoing a transformation, for example by exponentiating, to return predictions to the original scale.
Discussion Questions
- Why does taking logs turn exponential growth into a straight line?
- After fitting a line to log(y), why is the back-transformed prediction a median rather than a mean?
- What would you try if a scatterplot flattens out as x increases?
Practice Questions
- A scatterplot curves upward ever more steeply. Which transformation is a natural first try?
- If log(y) = 1 + 0.5x, what happens to y when x increases by 1?
- A residual plot from a linear fit shows a clear curve. What should you do next?
- In a log-log model the slope is 2. What does that say about the relationship between y and x?
- Why is extrapolation still risky after a successful transformation?
Show answers
- Take the logarithm of the response variable, y.
- y is multiplied by 10^0.5, about 3.16, if the log is base 10.
- Consider transforming one or both variables to straighten the relationship, then re-check the residual plot.
- y is roughly proportional to x², a power relationship with exponent 2.
- The transformed relationship may also change shape outside the observed range, so predictions beyond the data remain unreliable.