Modelling with transformed data
Put transformed data to work in Year 12 VCE General Mathematics. Once squaring, logging or taking reciprocals has straightened a scatterplot, a least squares line on the new values gives a curved model that fits the original data, such as the cost per person of a bus to Falls Creek, which drops sharply and then levels off as the group grows.
You will fit models like \(y = a + b\log x\) and \(\log y = a + bx\) with technology, then make predictions by transforming \(x\), substituting and undoing any change to \(y\). You will interpret \(b\) for a transformed variable, compare models using \(r^2\) and residuals, and remember that extrapolation stays risky.
Theory
After a transformation straightens the data, a least squares line on the transformed values becomes a powerful curved model. This Year 12 General Mathematics guide for students in Victoria shows how to fit models such as \(y = a + b\log x\), make predictions by transforming and undoing, interpret \(b\) and compare models with \(r^2\).
Once a transformation has straightened the data, a least squares line is fitted to the transformed data, in exactly the same way as before. If \(x\) was transformed, the model is \(y = a + bx^2\), \(y = a + b\log x\) or \(y = a + b \times \dfrac{1}{x}\). If \(y\) was transformed, it is \(y^2 = a + bx\), \(\log y = a + bx\) or \(\dfrac{1}{y} = a + bx\).
To fit the line with technology, make a new list of transformed values (for example \(\log x\) for every \(x\)) and use it in place of the original variable in the linear regression. The model is a straight line on the transformed axes and a curve on the original axes.
To make a prediction, transform the given \(x\) the same way, substitute, and if \(y\) was transformed, undo it at the end: square root for \(y^2\), \(10\) to the power for \(\log y\), reciprocal for \(\dfrac{1}{y}\). Predictions outside the range of the data are still extrapolation, and \(r^2\) for the transformed data compares how well different models fit.
Models after transforming \(x\) (fit \(y\) against the transformed values):
Models after transforming \(y\) (fit the transformed values against \(x\)):
Undoing a transformation of \(y\) to give the prediction:
Fitting and using a model on transformed data
- Transform. Calculate the transformed values for the chosen variable (a new row or list).
- Fit. Use linear regression with the transformed variable in place of the original one. Write the model with the transformation shown, for example \(y = a + b\log x\).
- Predict. Transform the given \(x\) (if \(x\) was transformed), substitute, and calculate.
- Undo. If the model gives \(y^2\), \(\log y\) or \(\dfrac{1}{y}\), convert back to \(y\) before answering in context.
- Judge. Compare \(r^2\) with other models, check the residuals, and say whether the prediction is interpolation or extrapolation.
Square the diameter first (the model uses the transformed value), then substitute.
| \(\text{diameter}^2\) | \(=\) | \(150^2\) |
| \(\text{diameter}^2\) | \(=\) | \(22500\) |
| \(\text{price}\) | \(=\) | \(15 + 0.012 \times 22500\) |
| \(\text{price}\) | \(=\) | \(15 + 270\) |
| \(\text{price}\) | \(=\) | \(285\) |
| \(\text{diameter}^2\) | \(=\) | \(300^2\) |
| \(\text{diameter}^2\) | \(=\) | \(90000\) |
| \(\text{price}\) | \(=\) | \(15 + 0.012 \times 90000\) |
| \(\text{price}\) | \(=\) | \(15 + 1080\) |
| \(\text{price}\) | \(=\) | \(1095\) |
The \(150\) cm rug costs \(\$285\) and the \(300\) cm rug costs \(\$1095\). Doubling the diameter roughly quadruples the price, because the model uses the diameter squared (the amount of wool depends on the area).
| Impressions \(x\) | \(10\) | \(100\) | \(1\,000\) | \(10\,000\) | \(100\,000\) |
| Enquiries \(y\) | \(12\) | \(19\) | \(25\) | \(33\) | \(40\) |
(b) Interpret \(b\).
(c) Predict the number of enquiries for \(5000\) impressions.
Each \(x\) is a power of \(10\), so \(X = \log x\) is exactly \(1, 2, 3, 4, 5\). Fit \(y\) against \(X\):
| \(S_{XX}\) | \(=\) | \(10\) |
| \(S_{Xy}\) | \(=\) | \(70\) |
| \(b\) | \(=\) | \(\dfrac{S_{Xy}}{S_{XX}}\) |
| \(b\) | \(=\) | \(7\) |
| \(\bar{X}\) | \(=\) | \(3\) |
| \(\bar{y}\) | \(=\) | \(25.8\) |
| \(a\) | \(=\) | \(\bar{y} - b\bar{X}\) |
| \(a\) | \(=\) | \(4.8\) |
| \(y\) | \(=\) | \(4.8 + 7\log x\) |
| \(\log 5000\) | \(\approx\) | \(3.6990\) |
| \(y\) | \(\approx\) | \(4.8 + 7 \times 3.6990\) |
| \(y\) | \(\approx\) | \(4.8 + 25.893\) |
| \(y\) | \(\approx\) | \(30.69\) |
(a) \(y = 4.8 + 7\log x\).
(b) Each increase of \(1\) in \(\log x\) means ten times as many impressions, so on average each tenfold increase in impressions adds about \(7\) enquiries.
(c) About \(31\) enquiries. Since \(5000\) is inside the data (\(10\) to \(100\,000\)), this is interpolation.
(a) Predict the number of visitors in week \(8\) and in week \(10\).
(b) What number of visitors does the model give at launch (\(x = 0\))?
Substitute \(x\) to get \(\log y\), then undo the log with \(y = 10^{\log y}\).
| \(\log y\) | \(=\) | \(1.8 + 0.15 \times 8\) |
| \(\log y\) | \(=\) | \(1.8 + 1.2\) |
| \(\log y\) | \(=\) | \(3\) |
| \(y\) | \(=\) | \(10^{3}\) |
| \(y\) | \(=\) | \(1000\) |
| \(\log y\) | \(=\) | \(1.8 + 0.15 \times 10\) |
| \(\log y\) | \(=\) | \(3.3\) |
| \(y\) | \(=\) | \(10^{3.3}\) |
| \(y\) | \(\approx\) | \(1995.26\) |
| \(\log y\) | \(=\) | \(1.8\) |
| \(y\) | \(=\) | \(10^{1.8}\) |
| \(y\) | \(\approx\) | \(63.10\) |
(a) About \(1000\) visitors in week \(8\) and \(1995\) in week \(10\). The answer \(3.3\) is \(\log y\), not the number of visitors.
(b) About \(63\) visitors at launch. Notice the model multiplies visitors by the same factor each week, so it would grow very fast if extended well past week \(12\): extrapolation is risky.
| People \(x\) | \(1\) | \(2\) | \(4\) | \(5\) | \(10\) | \(20\) |
| \(\dfrac{1}{x}\) | \(1\) | \(0.5\) | \(0.25\) | \(0.2\) | \(0.1\) | \(0.05\) |
| Cost per person \(y\) (\(\$\)) | \(631\) | \(328\) | \(182\) | \(149\) | \(91\) | \(59\) |
(b) Compare \(r^2\) for this model with \(r^2\) for a straight line fitted to \(y\) against \(x\).
(c) Predict the cost per person for a group of \(8\).
Use \(X = \dfrac{1}{x}\) (exact values in the table) as the explanatory variable:
| \(S_{XX}\) | \(=\) | \(0.63\) |
| \(S_{Xy}\) | \(=\) | \(378.35\) |
| \(b\) | \(=\) | \(\dfrac{S_{Xy}}{S_{XX}}\) |
| \(b\) | \(\approx\) | \(600.56\) |
| \(\bar{X}\) | \(=\) | \(0.35\) |
| \(\bar{y}\) | \(=\) | \(240\) |
| \(a\) | \(=\) | \(\bar{y} - b\bar{X}\) |
| \(a\) | \(\approx\) | \(29.81\) |
| \(y\) | \(\approx\) | \(29.81 + 600.56 \times \dfrac{1}{x}\) |
| \(r^2 \ (y \text{ against } \tfrac{1}{x})\) | \(\approx\) | \(0.9999\) |
| \(r^2 \ (y \text{ against } x)\) | \(\approx\) | \(0.48\) |
| \(\dfrac{1}{8}\) | \(=\) | \(0.125\) |
| \(y\) | \(=\) | \(29.81 + 600.56 \times 0.125\) |
| \(y\) | \(=\) | \(29.81 + 75.07\) |
| \(y\) | \(=\) | \(104.88\) |
(a) \(y = 29.81 + 600.56 \times \dfrac{1}{x}\).
(b) The reciprocal model explains about \(99.99\%\) of the variation in cost per person, compared with only about \(48\%\) for the straight line, so it is far better.
(c) About \(\$104.88\) per person. As the group gets very large, \(\dfrac{1}{x}\) approaches \(0\), so the cost per person levels off near \(a = \$29.81\).
Common pitfalls
Frequently asked questions
How do you fit a least squares line to transformed data?
Make a new list of the transformed values, such as log x for every x, and use it in place of the original variable in the calculator's linear regression. Write the model with the transformation, for example y = a + b log x.
How do you make a prediction from a log y model?
Substitute x to find log y, then undo the logarithm: y equals 10 to the power of that value. For example, log y = 3 gives y = 1000.
How do you interpret b in y = a + b log x?
An increase of 1 in log x means x is multiplied by 10, so b is the predicted change in y for each tenfold increase in x.
How do you compare a transformed model with a linear model?
Compare their r squared values: the model with the larger r squared explains more of the variation in the response. Also check that its residual plot shows no pattern.
Is extrapolation reliable with a transformed model?
No. A transformed model is still only supported inside the range of the data, and curved models such as log y can grow very quickly outside it.