Suppose the typical time to finish a task grows by roughly the same percentage, not the same number of minutes, with each extra level of difficulty, and the times spread out more as they grow. A straight line in minutes misses both the curve and the growing spread. Regression can still describe such a pattern, either by adding powers of the predictor or by modeling the logarithm of the response. This lesson explains both approaches and settles which original-scale quantity a model for log responses actually predicts.
Key terms
Polynomial regression
Definition A polynomial regression of degree models the conditional mean of a response given a numerical predictor as a polynomial in ,
that is, . It estimates the coefficients by least squares with the columns as predictors. The estimates are unique when the data contain at least distinct values of . When and the mean function is curved, so the change in the mean for a one-unit step in depends on where the step starts. For a quadratic
In plain words A quadratic curve is built by adding a constant, a straight-line part and a squared part. Equal steps in give unequal changes in the mean, so no single number is the slope. Once is in the model, the coefficient is not the change per unit of , because changing also changes . To compare two predictor values, evaluate the whole fitted function at both. Outside the range of the observed values a polynomial can bend sharply, and the data give no check on its shape there.
Example Take the mean function . Its values at are , , and , so successive one-unit steps raise the mean by , and . In general . The coefficient on matches none of these changes.
Linear in the coefficients
Definition A regression mean function is linear in the coefficients when it has the form
where are known functions of the predictors that contain no unknown parameters. Each can be computed from the data and used as a column of the design matrix, so least squares and the usual linear-model inference apply, under the same assumptions as for any other linear regression. Polynomials, the function for positive , and models with interaction terms are all linear in the coefficients. The mean function is not, because sits inside the exponential.
In plain words The word linear in linear regression describes how the unknown coefficients enter, each one multiplying a known column, and not the shape of the graph against . A curve in can be a linear model.
Example For the quadratic above, the design columns at are the constant column, the values of and the values of , and the mean vector is a weighted sum of them,
A multiplicative model with becomes linear in the coefficients after taking logs, . A model with an added error, , does not, because the logarithm of a sum does not split into a sum.
Log transformation
Definition Here is the natural logarithm, the inverse of with . It is defined only for positive arguments, and for . A log transformation replaces a positive variable by its logarithm. For a response measured in units, write with a fixed positive reference amount in the same units, such as one minute, so that the logarithm is taken of a pure number. A response transformation models in place of , which changes the scale on which the mean, the errors and their assumptions are stated. A predictor transformation uses as a predictor, which changes the shape of the mean function in and leaves the response scale alone.
In plain words On a log scale equal ratios become equal differences. Doubling is always the same step, , whether it goes from 1 to 2 minutes or from 4 to 8 minutes. That suits outcomes whose typical level changes by percentages rather than by fixed amounts. Zero and negative values have no logarithm, and replacing by to avoid zeros gives a different model whose conclusions depend on the chosen . A transformation does not repair dependent observations, biased sampling or predictions far outside the observed range.
Example Times of , , and minutes with minute have logs , , and , which are equally spaced. If each extra unit of a predictor doubles the time, the log of the time rises by at every step, and a straight line in describes it exactly. Changing the reference to minutes subtracts from every value and changes only the intercept.
Lognormal error
Definition A positive random variable is lognormal with parameters and when . The parameters are the mean and variance of , not of . A regression with lognormal error states that
where, given , the error is with the same for every , and errors of different observations are independent. On the original scale this reads
so the error multiplies the typical value instead of adding to it, and given the ratio is lognormal with parameters and .
In plain words A symmetric bell curve of errors on the log scale becomes a right-skewed distribution on the original scale. An error of multiplies the typical value by , while an error of multiplies it by , so deviations above the typical value stretch farther in original units than deviations below it. The spread in original units grows in proportion to the typical level, while the spread on the log scale stays fixed. Normality and constant variance are assumptions about the log scale, so residual plots from the log-scale fit are where they are checked. Predictions still need checking on the scale where they will be used.
Example A teaching model declares
with , so the log error has standard deviation . These coefficients are chosen for illustration, not estimated from data. At the quantity is normal with mean and variance .
Conditional median
Definition A conditional median of given is a number with and . For a continuous conditional distribution whose density is positive on an interval and zero outside it, such as a lognormal one, it is the unique value with . A strictly increasing function carries the median of a variable to the median of the new variable, and in the lognormal error model the log error has median . Hence
The same holds for any continuous log error with unique median , normal or not.
In plain words Exponentiating moves the middle of the log-scale distribution to the middle of the original-scale distribution, because an increasing function keeps values in the same order. Half of the modeled outcomes lie below the exponentiated value and half lie above it. Averages are not carried over in the same way.
Example In the teaching model at the mean and median of are both , so
One more unit of multiplies the median by , an increase of about percent, not an additive increase of units of .
Back-transformation
Definition Back-transformation converts a value on the log scale to the original scale by exponentiating it and multiplying by . Which original-scale quantity the result describes depends on the error model. Suppose the conditional mean of is , so that with an error of mean . Unless the error equals with probability , Jensen’s inequality gives , so is smaller than . Under the lognormal error model with constant variance ,
and therefore
that is, . If the log-error variance changes with , the factor changes with too, and for a log error that is not normal the factor that turns into the mean is under that distribution, while is the median only if the error has median . When the coefficients and are estimated, the values obtained by back-transformation are estimates and carry that uncertainty.
In plain words When the log error is symmetric about , as in the normal model, exponentiating a fitted mean log value estimates a typical value, the median, not an average. The long right tail on the original scale pulls the mean above the median, and more spread on the log scale pulls it further. Reporting the uncorrected value as a mean understates the mean, and any correction factor is only as trustworthy as the error model behind it.
Example In the teaching model , so at
about percent above the median . About percent of the modeled outcomes at this fall below the mean. With a log-error variance of instead, the median would stay the same and the mean-to-median factor would become . Because does not depend on here, each unit of multiplies the mean by , the same factor as for the median.
Check yourself
- A fitted quadratic is . Find the fitted change in the response from to and from to . Is the coefficient the change per unit of , and is this a linear model?
Show the answer
The fitted values at are , and , so the changes are and . In general the change from to is , which depends on , so the coefficient is not a per-unit change. The model is linear in the coefficients, since the coefficients , and multiply the known columns , and , even though the fitted curve rises and then falls.
- A model for repair times in hours states with hour, where is the number of faulty parts and for every . A report exponentiates the mean log value at and calls the result, hours, the average repair time. What does hours describe under this model, and what is the conditional mean?
Show the answer
The log error is normal with mean , so its median is also , and exponentiating the mean log value gives the conditional median. Under the model half of the repairs with no faulty parts take less than hours and half take longer. The conditional mean is
which is hours, about percent higher. Calling hours the average understates the mean by about half an hour, and it presents a statement about a typical repair as a statement about the long-run average. With estimated coefficients and an estimated variance both numbers would be estimates.
- In the same model, someone says that each extra faulty part adds hours to the mean repair time. Correct the claim. What changes if the log-error variance is at but at ?
Show the answer
The slope is a change on the log scale. One more faulty part multiplies the median by , an increase of about percent, and with a constant log-error variance it multiplies the mean by the same factor. In hours the change depends on the starting point. From to the median rises from to about hours, an increase of about hours, and the mean rises from about to about hours. If the variance grows from to , the median still grows by the factor , but the ratio of the means becomes
so the factor for the median no longer describes the mean.