Logs, Squares and Functional Form
Learn how squares and logarithms let a straight-line regression fit curves, and how to read the coefficients in each form.
Key takeaways
- A regression is still linear if it uses X² or the log of X, because the coefficients enter in a straight-line way.
- Adding a squared term lets the effect of X rise and then fall (or fall and then rise).
- With a squared term, the effect of X depends on its level, so you must compute it at specific values.
- Logs turn changes into percentages: coefficients become percent changes or elasticities.
- You choose a form using theory, a plot of the data, and residual checks, not by hunting for the highest R².
Imagine Jonas, who owns a small coffee shop and spends money on neighborhood ads. The first $100 of ads brings in a flood of new customers who had never heard of him. The tenth $100 mostly reaches people who already know the shop. If you plot sales against ad spending, you do not get a straight line. You get a curve that climbs fast, then flattens, and might even sag if he floods the town with so many flyers that people get annoyed.
Yet "linear regression" fits straight lines. Does that mean it cannot handle curves? Not at all. The word linear in linear regression means the model is linear in its coefficients, not in the variables. You can feed it squared variables, logarithms and other transformations, and it still finds the best coefficients the usual way. Choosing the shape of the relationship is called choosing the functional form, and it is one of the most useful skills in applied economics.
Squares: letting the slope change
To let a curve bend, add the square of the variable alongside the variable itself. Let Ads be spending in hundreds of dollars. Suppose Jonas's regression gives weekly sales (in hundreds of dollars) as:
Sales = 100 + 40 × Ads − 2 × Ads² The positive 40 says that at the start, more ads help. The negative −2 on the square says the benefit fades. Plug in several values:
Ads = 0: 100 + 0 − 0 = 100
Ads = 2: 100 + 80 − 8 = 172
Ads = 4: 100 + 160 − 32 = 228
Ads = 6: 100 + 240 − 72 = 268
Ads = 8: 100 + 320 − 128 = 292
Ads = 10: 100 + 400 − 200 = 300
Ads = 12: 100 + 480 − 288 = 292
Ads = 14: 100 + 560 − 392 = 268 Sales rise, level off at 300, then slip. The curve is a parabola.
The curve is steep at first and flat near the top. Past 10, more ads cost more than they bring.
The slope is no longer one number
With a square in the model, you cannot say "each extra $100 of ads adds so much." The gain depends on where you start. Between Ads = 2 and Ads = 4, sales rise from 172 to 228, a gain of 56 for 2 extra units, or 28 per unit. Between 8 and 10, sales rise from 292 to 300, a gain of 8 for 2 units, or 4 per unit. The rule for the instant slope is:
Slope at a given level = 40 − 4 × Ads At Ads = 3 the slope is 40 − 12 = 28, matching the 28 per unit we found between 2 and 4. At Ads = 10 it is 40 − 40 = 0, the flat top of the hill.
That top is the turning point, and there is a shortcut for finding it. For a model with b1 × X + b2 × X², the turning point is at X = −b1 ÷ (2 × b2).
Here b1 = 40 and b2 = −2, so the peak sits at 40 ÷ 4 = 10.
Always keep the plain X in the model when you add X². Dropping it forces the curve's turning point to sit at zero, which is almost never true. A reasonable question is whether the squared term is needed at all. Test it: if its t statistic is small, a straight line may be fine. If you add several squared terms or interactions together, use an F test (see the F test lesson).
Worked example: how much should Jonas spend?
Ads cost money, so more sales are not automatically better. Count each $100 of ads as one unit of cost, measured in the same hundreds of dollars as sales. Jonas's profit gain from the model (sales minus ad cost, ignoring other costs) is:
Profit = (100 + 40 × Ads − 2 × Ads²) − Ads
= 100 + 39 × Ads − 2 × Ads² Now apply the turning-point shortcut with b1 = 39 and b2 = −2: Ads = 39 ÷ 4 = 9.75. So the best level is $975 a week, a bit below the sales peak of $1,000. Check by comparing values. At Ads = 9: 100 + 351 − 162 = 289. At Ads = 9.75: 100 + 380.25 − 190.125 = 290.125. At Ads = 10: 100 + 390 − 200 = 290. The middle value wins, just barely.
The logic is worth saying in words. Keep adding ads while the next $100 brings in more than $100 of extra sales. The extra sales per unit are 40 − 4 × Ads, so you stop when 40 − 4 × Ads = 1, which gives Ads = 9.75 again. A straight-line model could never tell Jonas to stop: it would say "more is always better." The curve gives an answer with a stopping point.
A caution that belongs to every curve fit: this was an estimate from data, so the peak has a margin of error. The honest message is "somewhere near $1,000 a week," not "exactly $975."
Why this is still a linear regression
Software treats Ads² as just another column of numbers. You compute it once for each row, hand it to the regression as if it were a new variable (like temperature or price), and the usual machinery from the best-fit lesson finds the coefficients that make squared errors smallest. Nothing about the method changes. The same is true for logs. What would break the method is a coefficient that enters in a non-straight way, such as Y = a + X^b, where b sits in an exponent. That needs a different tool. For a model with logs and squares, you stay on familiar ground.
This also means all the earlier tools still apply: standard errors, t tests, F tests, dummy variables, and interaction terms can all sit in the same model next to a squared term.
Logs: from dollars to percentages
A logarithm (we use the natural log, written ln) squeezes big numbers together. For small changes, a change in ln(X) is approximately the percentage change in X, written as a decimal. If a price goes up 1%, ln(price) goes up by about 0.01. That makes logs wonderful for economics, where percentages are the natural language: raises, growth rates, price changes.
There are four common setups, and the interpretation of the slope differs in each.
| Form | Model | Reading the slope b |
|---|---|---|
| Level-level | Y = a + b × X | One more unit of X changes Y by b units |
| Log-level | ln(Y) = a + b × X | One more unit of X changes Y by about 100 × b percent |
| Level-log | Y = a + b × ln(X) | A 1% rise in X changes Y by about b ÷ 100 units |
| Log-log | ln(Y) = a + b × ln(X) | A 1% rise in X changes Y by about b percent |
Let us put numbers on each.
Log-level. A wage regression gives ln(Wage) = 1.8 + 0.07 × Education. Each extra year of schooling is linked to wages about 7% higher. The exact figure is e^0.07 − 1 ≈ 0.0725, or 7.25%; the quick reading of 7% is close because 0.07 is small.
Level-log. Jonas finds Sales = 50 + 20 × ln(Ads). Doubling ads raises ln(Ads) by ln(2) ≈ 0.693, so sales rise by about 20 × 0.693 ≈ 13.9. A 1% rise in ads adds about 20 ÷ 100 = 0.2 units of sales. This form builds in diminishing returns automatically: the same percent increase always buys the same dollar gain, and a percent of a big number is a big jump.
Log-log. A demand regression gives ln(Quantity) = 5 − 1.5 × ln(Price). Here b = −1.5 is an elasticity: a 1% rise in price goes with about a 1.5% fall in quantity. Because demand elasticity is the thing economists often want, log-log is a favorite for demand work. A rise of 10% in price predicts a fall of about 15% in quantity. (For big price changes, the approximation gets rougher.)
Logs on the Y side give percent changes in Y; logs on the X side give percent changes in X.
How do you pick a form?
No single test names the right form, but you have good clues.
- Theory. Economics often says relationships are in percentages (demand elasticity) or have diminishing returns (output from inputs). Start there.
- Plot the data. A scatterplot of Y against X, or of residuals against X, often shows a bend a straight line would miss. The residual-check lesson shows how to look for patterns.
- Skewed variables. Income, house prices and firm sizes pile up near the low end with a long tail of huge values. Taking logs often makes the relationship much closer to a straight line and tames extreme values.
- Test the extra terms. Add X² and see if it is significant.
Your choice also shapes what you are claiming, so make it before you look for a pretty result. See the variable choice lesson for the habits that keep you honest.
Common mistakes
Comparing R² across different dependent variables. A model for Y and a model for ln(Y) explain different things. Their R² values are not comparable, even though both are printed in the same format. Judge them by residual plots and by what makes economic sense.
Taking the log of zero or negative numbers. ln(0) does not exist, and ln of a negative number does not either. If a variable has zeros, such as zero ads in some weeks, think carefully before logging it. Adding a small constant is a common patch, but it changes the interpretation and can affect results, so say that you did it.
Forgetting that the slope moves with a square. Quoting b1 alone as "the effect of X" when X² is in the model is wrong. Compute b1 + 2 × b2 × X at a value of X you care about.
Treating percent change and percentage points as the same. If a rate goes from 5% to 6%, that is one percentage point but a 20% rise in the rate. In a log-level model with a rate on the right side, "per unit" means per percentage point.
Pushing the curve beyond the data. The peak at Ads = 10 comes from data that may have covered only 0 to 14. Predicting Ads = 40 trusts the parabola far outside what you observed, where it may not apply.
Words to know
Functional form the mathematical shape, such as straight, squared or logged, that a regression assigns to a relationship.
Quadratic term a squared variable added to a model so the slope can change as the variable grows.
Turning point the value of X where a squared model changes from rising to falling or the reverse.
Natural logarithm (ln) a transformation under which small changes approximate percentage changes.
Elasticity the percent change in one variable that goes with a 1% change in another.
Log-log model a regression with the log of Y on the left and the log of X on the right.
Diminishing returns the pattern in which each extra unit of input adds less than the one before.
Check yourself
- Why is a regression with X² in it still called a linear regression?
- Using Sales = 100 + 40 × Ads − 2 × Ads², compute predicted sales at Ads = 5.
- For the same model, what is the slope at Ads = 6, and what does it say?
- In ln(Quantity) = 5 − 1.5 × ln(Price), what happens to quantity, approximately, if price rises 4%?
- In ln(Wage) = 1.8 + 0.07 × Education, interpret the 0.07.
- Explain why you should not compare the R² of a model for Y with the R² of a model for ln(Y).
Show the answers
- It is linear in the coefficients, so the usual method still finds them even though the curve bends in X.
- 100 + 40 × 5 − 2 × 25 = 100 + 200 − 50 = 250.
- Slope = 40 − 4 × 6 = 16, so near Ads = 6 each extra unit of ads adds about 16 units of sales.
- About a −1.5 × 4 = −6% change, so quantity falls roughly 6%.
- Each extra year of education goes with wages about 7% higher (exactly about 7.25%), holding other things fixed.
- They explain different variables, so each R² measures the share of different variation; compare them by residual plots and theory instead.