Sub topic 18
Functional Forms and Log Transformations
Prerequisites and the choice of form
Assume you know algebra, logarithms, means, variance, and the simple linear regression model. A regression is linear when it is linear in its unknown coefficients, even if a variable is transformed.
The basic model is:
Y_i = b_0 + b_1X_i + \varepsilon_iThis form assumes that one unit of change in \(X\) has the same effect on \(Y\) everywhere. A scatter plot may show that this assumption is unrealistic. Common alternatives include:
- Quadratic: \(Y=b0+b1X+b_2X^2+\varepsilon\)
- Exponential: \(Y=ae^{bX}\)
- Log-linear: \(\ln(Y)=b0+b1X+\varepsilon\)
- Log-log: \(\ln(Y)=b0+b1\ln(X)+\varepsilon\)
A transformed model can describe curvature while still allowing ordinary least squares to estimate its coefficients.
import numpy as np
from scipy import stats
x = np.array([1, 2, 3, 4, 5], dtype=float)
y = np.array([2.1, 3.9, 6.2, 7.8, 10.1])
# Log-linear model: ln(y) = b0 + b1*x
result = stats.linregress(x, np.log(y))
print("intercept:", result.intercept)
print("slope:", result.slope)
print("growth factor per x unit:", np.exp(result.slope))Interpreting logarithmic coefficients
The interpretation depends on which variable is logged.
| Model | Interpretation of \(b_1\) |
|---|---|
| \(Y=b_0+b_1X\) | A one-unit increase in \(X\) changes \(Y\) by \(b_1\) units |
| \(\ln(Y)=b_0+b_1X\) | A one-unit increase in \(X\) changes \(Y\) by approximately \(100b_1\)% |
| \(Y=b_0+b_1\ln(X)\) | A 1% increase in \(X\) changes \(Y\) by approximately \(b_1/100\) units |
| \(\ln(Y)=b_0+b_1\ln(X)\) | A 1% increase in \(X\) changes \(Y\) by approximately \(b_1\)% |
The approximations become less accurate for large changes. For a log-linear model, the exact percentage change from increasing \(X\) by one unit is:
100(e^{b_1}-1)\%In a log-log model, \(b_1\) is an elasticity. Elasticity measures the percentage response in \(Y\) to a percentage change in \(X\).
Transformations, predictions, and errors
Logarithms require positive values. You cannot directly take \(\ln(0)\) or the logarithm of a negative observation. Adding a constant may permit calculation, but it changes the model's meaning and requires justification.
When predicting the original \(Y\) from a log-\(Y\) model, exponentiating the fitted log value can produce a biased estimate of the arithmetic mean because errors were modeled on the log scale. The back-transformed value is often closer to a median prediction. Interpret the scale of the model before reporting results.
Use residual plots to check whether a transformation improves linearity and stabilizes the error variance. A better \(R^2\) alone is not enough, especially because \(R^2\) values from models using different dependent-variable scales are not directly comparable.
Exercise
In the model ln(Y) = 0.4 + 0.8 ln(X), what does a 1% increase in X imply?
Show answer
It implies an approximate 0.8% increase in Y.