Data transformations
Straighten curved data with data transformations in Year 12 VCE General Mathematics. Water flow through an irrigation pipe near Shepparton grows with the square of its diameter, and an e-bike loses value quickly before levelling off. A straight line fits neither, but squaring, logging or taking reciprocals of one variable can make the pattern linear.
You will calculate squared, log and reciprocal values, read the shape of a scatterplot, and use the circle of transformations to pick a transformation for \(x\) or \(y\). You will compare \(r\) before and after and use residual plots to confirm the result, ready to fit and use a least squares line on the transformed data.
Theory
A data transformation can turn a curved scatterplot into a straight one. This Year 12 General Mathematics guide for students in Victoria shows how to apply square, log and reciprocal transformations to one axis, choose them with the circle of transformations, and check the result with \(r\) and residual plots.
Many scatterplots curve. A data transformation replaces the values on one axis with new values so that the transformed points lie close to a straight line. The transformations used are the square (\(x^2\) or \(y^2\)), the logarithm base \(10\) (\(\log x\) or \(\log y\)) and the reciprocal (\(\dfrac{1}{x}\) or \(\dfrac{1}{y}\)). Only one variable is transformed at a time; the other keeps its original values.
The shape of the scatterplot decides which transformations can work. The circle of transformations matches each of four curved shapes to its transformations. Squaring stretches large values, so it straightens a curve that is flattening out along that axis; log and reciprocal squash large values, so they straighten a curve that is getting steeper along that axis.
To check whether a transformation has worked, compare Pearson's correlation coefficient \(r\) before and after (closer to \(1\) or \(-1\) means more linear) and look at the residual plot: a curved pattern should become random scatter.
The six transformations, each applied to one axis only:
Logarithms are base \(10\): \(\log x\) is the power of \(10\) that gives \(x\).
Circle of transformations (shape of the scatterplot and the transformations that can linearise it):
Linearising data with a transformation
- Describe the shape. Is the scatterplot increasing or decreasing? Is it levelling off or getting steeper?
- Use the circle. Find the matching quadrant and list its transformations.
- Transform one axis. Calculate the new values (for example \(\log x\) for every \(x\)) in a new row of the table or a new list on your calculator. Leave the other variable unchanged.
- Compare \(r\). Find \(r\) for the original and the transformed data. The transformation whose \(r\) is closest to \(1\) in size gives the most linear plot.
- Check the residual plot. Random scatter about zero confirms the transformed data are linear; a remaining pattern means the transformation has not fully worked.
Apply each transformation to every value. Three of them worked in full:
| \(20^2\) | \(=\) | \(400\) |
| \(\log 20\) | \(\approx\) | \(1.3010\) |
| \(\log 20\) | \(\approx\) | \(1.30\) |
| \(\log 1000\) | \(=\) | \(\log 10^3\) |
| \(\log 1000\) | \(=\) | \(3\) |
| \(\dfrac{1}{8}\) | \(=\) | \(0.125\) |
| \(x\) | \(4\) | \(8\) | \(20\) | \(50\) | \(1000\) |
| \(x^2\) | \(16\) | \(64\) | \(400\) | \(2500\) | \(1\,000\,000\) |
| \(\log x\) | \(0.60\) | \(0.90\) | \(1.30\) | \(1.70\) | \(3.00\) |
| \(\dfrac{1}{x}\) | \(0.25\) | \(0.125\) | \(0.05\) | \(0.02\) | \(0.001\) |
Squaring makes large values much larger, while log and reciprocal shrink them: \(1000\) becomes \(1\,000\,000\), \(3\) and \(0.001\). That is why they straighten different shapes.
Read the shape of the scatterplot, then use the circle of transformations.
| \(\text{shape}\) | \(\) | \(\text{decreasing, levelling off}\) |
| \(\text{quadrant}\) | \(=\) | \(3\) |
| \(\text{transformations}\) | \(\) | \(\log x,\ \dfrac{1}{x},\ \log y,\ \dfrac{1}{y}\) |
The value falls quickly at first and then levels off, so the shape is quadrant 3. Any one of \(\log x\), \(\dfrac{1}{x}\), \(\log y\) or \(\dfrac{1}{y}\) could linearise the data (all ages are positive, so log and reciprocal can be used). \(x^2\) and \(y^2\) would not help: they belong to other quadrants and would make this curve bend more.
| Diameter \(x\) (cm) | \(2\) | \(3\) | \(4\) | \(5\) | \(6\) | \(7\) |
| Flow \(y\) (L/min) | \(3.4\) | \(7.0\) | \(12.6\) | \(20.3\) | \(28.5\) | \(39.6\) |
Increasing and getting steeper is quadrant 4: \(x^2\), \(\log y\) or \(\dfrac{1}{y}\). Transform, then find \(r\) with technology:
| \(x^2\) | \(\) | \(4,\ 9,\ 16,\ 25,\ 36,\ 49\) |
| \(\log y\) | \(\approx\) | \(0.531,\ 0.845,\ 1.100,\ 1.307,\ 1.455,\ 1.598\) |
| \(r \ (y \text{ against } x)\) | \(\approx\) | \(0.985\) |
| \(r \ (y \text{ against } x^2)\) | \(\approx\) | \(1.000\) |
| \(r \ (\log y \text{ against } x)\) | \(\approx\) | \(0.987\) |
Both transformations raise \(r\) from \(0.985\), but \(y\) against \(x^2\) gives \(r \approx 1.000\), much closer to \(1\) than \(0.987\). The \(x^2\) transformation linearises the data better, which makes sense: the flow depends on the area of the pipe's opening, and area depends on the diameter squared.
| Hours \(x\) | \(1\) | \(2\) | \(4\) | \(6\) | \(8\) | \(12\) | \(16\) |
| Score \(y\) | \(22\) | \(31\) | \(40\) | \(46\) | \(49\) | \(55\) | \(58\) |
Increasing and levelling off is quadrant 2, so \(\log x\) is a sensible choice. Compare:
| \(r \ (y \text{ against } x)\) | \(\approx\) | \(0.928\) |
| \(r \ (y \text{ against } \log x)\) | \(\approx\) | \(1.000\) |
For \(y\) against \(x\), the residuals are negative, then positive, then negative again: a curved pattern, so a linear model does not suit the original data even though \(r \approx 0.928\). For \(y\) against \(\log x\), the residuals are small and randomly scattered about zero, and \(r\) rises to \(1.000\). The \(\log x\) transformation has linearised the data.
Common pitfalls
Frequently asked questions
What is a data transformation in statistics?
It is replacing the values of one variable with their squares, logarithms (base 10) or reciprocals so that a curved scatterplot becomes linear. Only one axis is transformed at a time.
What is the circle of transformations?
It is a circle drawn on a set of axes. Each quarter shows a curved scatterplot shape and lists the transformations that can straighten it, for example log x, 1/x, log y or 1/y for data that decrease and level off.
How do you know which transformation to use?
Describe the shape: increasing or decreasing, and levelling off or getting steeper. Find that shape on the circle of transformations, try its transformations, and keep the one whose r is closest to 1 in size and whose residual plot shows no pattern.
Which transformation straightens data that increase and level off?
Data that increase and level off match quadrant 2 of the circle: y squared, log x or 1/x can linearise them.
How can you tell if a transformation has worked?
The size of r should be closer to 1 for the transformed data, and the residual plot for the transformed data should show random scatter about zero instead of a curve.
Why can't you take log x when x is 0?
There is no power of 10 that gives 0, so log 0 does not exist, and 1/0 is undefined too. Log and reciprocal transformations need all the values being transformed to be positive.