Log-log transforms and power models
Taller redwoods have thicker trunks, but height grows more slowly than diameter and the straight line leaves an arch in its residual plot. Taking the log of height alone does not fix it. What does?
Where you are 9 in Bivariate data
When you reach for it
Transforming to linearity: logs and exponential models fitted the least-squares line to (x, \log y) and undid the log to get an exponential model \hat{y} = A B^x, the right shape when y is multiplied by the same factor for each one-unit step in x. Many relationships work differently: y is multiplied by the same factor each time x is multiplied by a fixed amount. Doubling a tree’s trunk diameter does not double its height; it multiplies it by roughly the same factor whether the trunk goes from 20 to 40 centimeters or from 100 to 200. That is a power model,
with a constant A > 0 and an exponent p. Reach for it when the straight line leaves a curve in its residual plot, the curve survives taking \log y alone, and the log of both variables gives a plot that is straight with a residual plot that has no pattern.
Semi-log plots: straightening exponential data with logarithms showed an exact power law becoming a straight line on log-log axes. Here the data scatter, so the line is the least-squares line and the residual plots do the deciding.
The procedure
Why both logs. If y = A x^{p} exactly, the laws of logarithms give
a straight line in \log x with slope p and intercept \log A. So when the data follow a power model with scatter, the pairs (\log x, \log y) lie in a straight band, and the least-squares line
is the natural fit. Taking \log y alone gives \log y = \log A + p \log x plotted against x, not \log x: that is a log curve, which still bends, so the arch stays.
Deciding. Fit the line on the raw data and look at its residual plot: an arch or a U says a line is the wrong shape. Then fit \log y on x and \log y on \log x. Both have the same response, \log y, so their r squared values may be compared fairly, but the residual plots decide: keep the one whose residual plot is patternless.
Back-transforming. Raise 10 to each side of the fitted line. Since 10^{b \log x} = x^{b},
The slope of the log-log line is the exponent. With natural logs on both variables, A = e^{a} and the slope is the same p: changing the base multiplies \log x and \log y by the same constant, which leaves the slope unchanged and multiplies only the intercept.
What the exponent means. For two values x_1 and x_2, the model’s predictions are in the ratio
so multiplying x by k multiplies the prediction by k^{p}, whatever x was. A 1\% increase in x multiplies \hat{y} by 1.01^{p} \approx 1 + 0.01p: a 1 percent change in x goes with about a p percent change in y. The approximation is close for small changes, not large ones.
Worked examples
The straight line leaves an arch
Hery, Fanja and Tiana measure eight redwoods in a grove (made-up data). As pairs (trunk diameter at chest height x in centimeters, height y in meters): (12, 14), (25, 21), (40, 28), (60, 37), (85, 48), (120, 54), (170, 71), (240, 82). Technology gives \hat{y} = 16.28 + 0.2989x with r = 0.982. Is a line a fair model?
SolutionA high r says the dots hug a line closely, not that a line is the right shape, so make the residual plot. For the first tree the line predicts 16.28 + 0.2989(12) = 19.87, and the residual is 14 - 19.87 \approx -5.9 meters. All eight residuals, in order of diameter:
They are negative at both ends and positive in the middle: an arch. The heights bend to the right, gaining less per centimeter of diameter as trees get thicker. Between the two thinnest trees height rises \displaystyle \frac{21 - 14}{25 - 12} \approx 0.54 meters per centimeter; between the two thickest, \displaystyle \frac{82 - 71}{240 - 170} \approx 0.16. A line is the wrong shape.
Which logs straighten it?
Fanja fits \log y on x and gets \widehat{\log y} = 1.2940 + 0.00307x with r = 0.913. Tiana fits \log y on \log x and gets \widehat{\log y} = 0.4879 + 0.6050\log x with r = 0.9984. Use the residuals to choose.
SolutionLogs are to four decimal places. A residual is the actual \log y minus the predicted. For the first tree, Fanja’s line predicts 1.2940 + 0.00307(12) = 1.3308, so her residual is 1.1461 - 1.3308 = -0.1847; Tiana’s predicts 0.4879 + 0.6050(1.0792) = 1.1408, residual 1.1461 - 1.1408 = 0.0053. The logs, then the two sets of residuals:
| x | \log x | \log y |
|---|---|---|
| 12 | 1.0792 | 1.1461 |
| 25 | 1.3979 | 1.3222 |
| 40 | 1.6021 | 1.4472 |
| 60 | 1.7782 | 1.5682 |
| 85 | 1.9294 | 1.6812 |
| 120 | 2.0792 | 1.7324 |
| 170 | 2.2304 | 1.8513 |
| 240 | 2.3802 | 1.9138 |
| x | Fanja’s residual | Tiana’s residual |
|---|---|---|
| 12 | -0.1847 | 0.0053 |
| 25 | -0.0486 | -0.0114 |
| 40 | 0.0304 | -0.0100 |
| 60 | 0.0900 | 0.0045 |
| 85 | 0.1262 | 0.0260 |
| 120 | 0.0700 | -0.0134 |
| 170 | 0.0354 | 0.0140 |
| 240 | -0.1170 | -0.0141 |
Fanja’s residuals are negative at both ends and positive in the middle: the arch survived, because logging y alone bends a curve that was already bending the same way. Tiana’s are mixed in sign across the whole range, with no arch and no fan. Both lines describe \log y, so their r squared values, 0.913^2 \approx 0.834 and 0.9984^2 \approx 0.997, measure the same thing and agree with the plots. The log-log fit is the one to use.
Back to a power model
Turn Tiana’s line into a model \hat{y} = A x^{p} and interpret A and p.
SolutionRaise 10 to each side: A = 10^{0.4879} \approx 3.075 and p = 0.6050, so
The exponent says height grows like diameter to about the 0.6 power: slower than in proportion. A is the predicted height of a tree 1 centimeter thick, far below the smallest trunk measured, so it has no meaning on its own; it sets the scale of the curve.
What the exponent says
By what percent does the model’s height change for a 1\% thicker trunk? For a doubled diameter? Compare the predicted heights of trees 60 and 240 centimeters thick.
SolutionThe ratio of predictions is \displaystyle \left(\frac{x_2}{x_1}\right)^{0.605}, and A cancels. A 1\% thicker trunk gives 1.01^{0.605} \approx 1.0060, about 0.6\% taller. A doubled trunk gives 2^{0.605} \approx 1.521, about 52\% taller, the same at 20 centimeters as at 120. The 240 centimeter trunk is 4 times as thick as the 60, so its predicted height is 4^{0.605} \approx 2.31 times as great. Check: 3.075(240)^{0.605} \approx 84.7 and 3.075(60)^{0.605} \approx 36.6, and \displaystyle \frac{84.7}{36.6} \approx 2.31.
Judging in meters and predicting
Find the power model’s residual for the tree 85 centimeters thick, in meters and as a percent. Compare the power model’s spread of residuals in meters with the line’s, s \approx 4.9 meters. Then predict heights for diameters of 150 and 400 centimeters with both models.
SolutionPredict on the log scale, then back-transform. For x = 85, \widehat{\log y} = 0.4879 + 0.6050\log 85, about 1.6552, so \hat{y} = 10^{1.6552} \approx 45.2 meters, and the residual is 48 - 45.2 = 2.8 meters. On the log scale the residual is 0.0260, and 10^{0.0260} \approx 1.062: the tree is about 6.2\% taller than the model predicts, the largest miss in the data.
The power model’s residuals in meters, in order of diameter, are
and their standard deviation, with n - 2 = 6 in the denominator as for s, is about 2.0 meters, against 4.9 for the line. The power model’s predictions are typically less than half as far off.
For x = 150: \widehat{\log y} \approx 1.8044 and \hat{y} = 10^{1.8044} \approx 63.7 meters; the line gives 16.28 + 0.2989(150) \approx 61.1. For x = 400: \widehat{\log y} \approx 2.0621 and \hat{y} \approx 115.4 meters; the line gives 135.8.
At 150 centimeters, inside the data, the power model is the one to trust; its residuals showed no pattern. A 400 centimeter trunk is far past the thickest tree measured, an extrapolation. The two models already disagree by about 20 meters there, and nothing in eight trees says the curve keeps its shape for giants.
Boundaries
- Both variables must be positive. A 0 or a negative value has no logarithm, and the model A x^{p} is fitted only for x > 0.
- Log-log straightens power relationships, those where multiplying x by k multiplies y by about k^{p}. Growth by a constant factor per unit of x is exponential and needs \log y on x alone (Transforming to linearity: logs and exponential models). The residual plot of the transformed fit says which.
- The least-squares line makes the squared residuals of \log y small, not those of y. Back- transformed predictions estimate a typical value at that x and tend to sit a little below the mean of y there.
- r squared values compare fairly only between fits with the same response: \log y on x against \log y on \log x, yes; \log y against y, no.
- “A 1\% change in x gives about a p\% change in y” is an approximation for small changes. For large ones use k^{p} exactly.
- Predictions outside the range of x in the data are extrapolations, on either side.
Where this goes next
Exponential and power models are the two shapes logarithms straighten; together with the line they cover much of what regression in a first statistics course meets. How well a fit does, through r squared and s, is the subject of r squared and the standard deviation of the residuals, and inference for regression reads residual plots on whatever scale the line was fitted, so a transformation chosen here carries into Conditions for regression inference.
Exercises
Power models from fitted lines
- A line fitted to log-log data is \widehat{\log y} = 0.3 + 0.75\log x. Write the power model.
- A line fitted with natural logs is \widehat{\ln y} = 1.2 + 0.4\ln x. Write the power model.
- A fit gives \widehat{\log y} = 2.1 - 0.5\log x. Write the power model and say how the prediction changes when x rises by 1\%.
- Write the model \hat{y} = 2.5x^{0.8} as a line in \log x and \log y.
The exponent
- A power model has p = 0.7. By about what percent does the prediction change when x rises by 1\%? When x doubles?
- A model is \hat{y} = A x^{-0.5}. What happens to the prediction when x is multiplied by 4?
- Using the redwood model \hat{y} = 3.075x^{0.605}, how many times taller is the predicted height of a tree 90 centimeters thick than one 30 centimeters thick?
Fitting, judging, predicting
- Hery measures the crown width of six redwoods (made-up data), as pairs (trunk diameter in centimeters, crown width in meters): (20, 7.0), (35, 10.6), (55, 14.4), (80, 19.6), (110, 23.9), (150, 31.0). Use technology to fit the least-squares line of \log y on \log x, with coefficients to four decimal places, and write the power model.
- Use the line from Exercise 8 to predict the crown width of a tree 100 centimeters thick. Its crown is 21.5 meters wide. Find the residual in meters and on the log scale.
- For the crown data of Exercise 8, the residuals of the line of \log y on x are -0.0950, 0.0147, 0.0538, 0.0703, 0.0155, -0.0594, and those of the line of \log y on \log x are 0.0010, 0.0030, -0.0079, 0.0067, -0.0085, 0.0057. Describe each residual plot and choose a model.
- On the log-log scale, one residual is 0.03 and another is -0.02. Say what each means as a percent of the prediction.
- Use the redwood line \widehat{\log y} = 0.4879 + 0.6050\log x to predict the height of a tree 300 centimeters thick. How far should the answer be trusted?
- Use the same line to predict the height of a sapling 2 centimeters thick. Comment.
- Tiana refits the redwood data with natural logs, \ln y on \ln x. Without refitting, give her slope and intercept.
Reasoning
- Show that if y = A x^{p} with A > 0 and x > 0, then \log y is a linear function of \log x, and name its slope and intercept.
- Explain why switching from base-10 logs to natural logs on both variables changes the intercept of the log-log line but not its slope.
- Why does taking \log y alone fail to straighten data that follow a power model with 0 < p < 1?
- Explain why “a 1\% change in x goes with about a p\% change in y”, and why the word “about” is needed.
- A tree’s diameter is recorded as 0 by mistake. Why must that case be fixed or removed before a log-log fit?
Answers
- A = 10^{0.3} \approx 1.995, so \hat{y} = 1.995x^{0.75}.
- A = e^{1.2} \approx 3.320, so \hat{y} = 3.320x^{0.4}.
- A = 10^{2.1} \approx 125.9, so \hat{y} = 125.9x^{-0.5}. A 1\% rise multiplies the prediction by 1.01^{-0.5} \approx 0.9950, a drop of about 0.5\%.
- \log 2.5 \approx 0.3979, so \widehat{\log y} = 0.3979 + 0.8\log x.
- 1.01^{0.7} \approx 1.0070, about 0.7\%. 2^{0.7} \approx 1.6245, about 62.5\%.
- It is multiplied by 4^{-0.5} = 0.5: halved.
- \displaystyle \left(\frac{90}{30}\right)^{0.605} = 3^{0.605} \approx 1.94 times.
- \widehat{\log y} = -0.1097 + 0.7331\log x. Then A = 10^{-0.1097} \approx 0.7768, so \hat{y} = 0.7768x^{0.7331}.
- \widehat{\log y} = -0.1097 + 0.7331(2) = 1.3565, so \hat{y} = 10^{1.3565} \approx 22.7 meters. The residual is 21.5 - 22.7 = -1.2 meters, and on the log scale \log 21.5 - 1.3565 \approx -0.0241.
- The \log y on x residuals are negative at both ends and positive in the middle, an arch. The log-log residuals are small and mixed in sign with no shape. Use the power model.
- 10^{0.03} \approx 1.072: about 7.2\% above the prediction. 10^{-0.02} \approx 0.955: about 4.5\% below.
- \log 300 \approx 2.4771, so \widehat{\log y} \approx 1.9866 and \hat{y} \approx 97.0 meters. A 300 centimeter trunk is past the thickest tree in the data, 240, so this is an extrapolation.
- \log 2 \approx 0.3010, so \widehat{\log y} \approx 0.6700 and \hat{y} \approx 4.7 meters. The thinnest tree in the data is 12 centimeters thick, so this extrapolates below the data and should not be trusted.
- Slope 0.6050, unchanged. Intercept 0.4879 \times \ln 10, which is 0.4879 \times 2.3026 \approx 1.1234.
- By the product law, \log(A x^{p}) = \log A + \log x^{p}, and by the power law \log x^{p} = p\log x. So \log y = \log A + p\log x. With u = \log x this is \log A + p\,u: slope p, intercept \log A.
- \ln v = (\ln 10)\log v for every positive v, so both coordinates are multiplied by \ln 10. Multiplying both by the same constant leaves every rise over run, and so the least-squares slope, unchanged, while the intercept, a value of \ln y, is multiplied by \ln 10.
- \log y = \log A + p\log x plotted against x is a log curve: it rises quickly for small x and levels off, the same bend the raw data had. Only plotting against \log x makes it straight.
- Raising x by 1\% multiplies the prediction by 1.01^{p}, and for small changes 1.01^{p} \approx 1 + 0.01p, a rise of about p\%. The match is not exact: 1.01^{0.605} is 1.00604, not 1.00605, and for larger changes the gap grows.
- \log 0 is not defined: no power of 10 equals 0. The case cannot be placed on the log-log plot.