Multiple regression: comparing with the other variables held fixed
Do people who drink more coffee have lower blood pressure? In made-up data, it looks that way if you put in coffee alone. Add age and the coefficient flips its sign. This page carries on from the short look at multiple regression in section 11 of correlation and regression: why coefficients change, what wobbles when inputs look alike, and how to read how well the model fits. All data here is made up, and the page explains statistics ideas only.
Short answer. Multiple regression guesses y from several inputs, as in y = b₀ + b₁x₁ + b₂x₂ + …. The coefficient b₁ means "with the other inputs held fixed, when x₁ goes up by 1, y changes by b₁", which is why it is called an adjusted coefficient. When inputs are tangled together, adding or dropping one can change a coefficient a lot, and when inputs look too much alike, a coefficient wobbles a lot from sample to sample.
Definitions
The page below explains with two inputs, but the definitions are the same for p inputs. Write for the outcome of person i and for the value of input j (i = 1, …, n, j = 1, …, p).
- multiple regression model
- A model that writes the outcome as a linear expression in the inputs plus an error. The errors are taken to be independent, with mean 0 and the same variance (confidence intervals and p-values also assume a normal distribution).
- regression coefficient
- The values that make the sum of squared residuals as small as possible are the least-squares estimates of . is how much the prediction goes up when goes up by 1 with every other input held the same. If is the residual from regressing on the other inputs, equals the slope of the simple regression of y on that residual.
- residual
- The difference between an observed value and its prediction.
- coefficient of determination
- The share of the variation in y that the regression explains. Adding an input never lowers it.
- adjusted R²
- The sum of squared residuals and the variation in y, each divided by its degrees of freedom, then compared. It is penalised as the number of inputs p grows.
- multicollinearity and the variance inflation factor (VIF)
- Multicollinearity is a strong linear relationship among the inputs that makes the variance of the coefficient estimates large. With the coefficient of determination from regressing on the other inputs, the factor by which the variance grows is the variance inflation factor (σ² is the error variance).
- dummy variable
- An input that shows a category with 0 and 1. With k categories, make k − 1 of them, leaving out the reference category. The dummy for category m is 1 for people in that category and 0 otherwise. Its coefficient is the mean difference between that category and the reference category when the other inputs are the same.
1. Adding a variable changes the coefficient
Here are cups of coffee a day and systolic blood pressure for 60 made-up people (20 each in their 30s, 50s and 70s). When making the data we decided that "older people drink less coffee and have higher blood pressure" and that "at the same age, each cup adds 2 mmHg".
Dot colour is the age group. With "Add age too", the three coloured lines are the blood pressure the multiple regression guesses with age held at that group's mean (about 35, 55 and 74). They all have the same slope b₁, so they are parallel.
Try this. ① "Coffee only": blood pressure = 150.7 − 3.79 × coffee. One more cup gives a guess 3.79 mmHg lower. R² = 0.21. ② "Add age too": blood pressure = 106.1 + 1.6 × coffee + 0.52 × age. Comparing people of the same age, one more cup goes with 1.6 mmHg higher blood pressure. The sign flipped, and R² rose to 0.71. ③ The true value used to make the data is 2. With a sample of 60 it was estimated at 1.6, with a standard error of 0.8 (step ④ of "how the formula is built" in section 4).
Why it changes. People in their 30s drink 3.87 cups on average and have blood pressure 130.65; people in their 70s drink 2.15 cups and have 148.85. With coffee alone, the line sees "less coffee = older = higher blood pressure" all at once. The part of blood pressure that age raised leaks into the coffee slope and makes it go downhill. Put age in, and age's coefficient takes that part, leaving the coffee coefficient with only the difference within the same age. A hidden value tied to both inputs like this is confounding (confounding and bias), and a direction that flips when groups are combined is called Simpson's paradox.
There is an exact formula linking the two. Call δ the slope that guesses age from coffee. Then slope with coffee only = b₁ + b₂ × δ. In this data δ = −10.27 years (someone who drinks one more cup is about 10 years younger on average), so 1.6 + 0.52 × (−10.27) gives the coffee-only slope −3.79 (the numbers are rounded, so multiplying them by hand gives slightly different last digits). The coefficient only changes when the left-out variable is related to y (b₂ ≠ 0) and tangled with the input you kept (δ ≠ 0). If either is 0, it makes no difference whether you add it.
2. The formula and the arithmetic with two inputs
In y = b₀ + b₁x₁ + b₂x₂ the coefficients are picked by least squares, as in simple regression. With two inputs, take the mean away from each value and solve these two equations together (the normal equations).
S₁₁ = Σ(x₁ − x̄₁)², S₂₂ = Σ(x₂ − x̄₂)², S₁₂ = Σ(x₁ − x̄₁)(x₂ − x̄₂), S₁y = Σ(x₁ − x̄₁)(y − ȳ), and S₂y has the same shape. Solving gives
If the inputs are uncorrelated (S₁₂ = 0), b₁ equals the simple regression slope S₁y ÷ S₁₁. The denominator can be written S₁₁ × S₂₂ × (1 − r₁₂²), where r₁₂ is the correlation between the two inputs. The more the inputs look alike (r₁₂ near ±1), the closer the denominator gets to 0 and the shakier the coefficients become. That is section 4. The labs on this page compute exactly this formula. With three or more inputs the same thing is done with matrices, and statistics tools do it for you.
Reading a coefficient. The unit of b₁ is "unit of y ÷ unit of x₁" (mmHg per cup here). Because the units differ, do not compare the sizes of b₁ and b₂ to say which one "matters more". b₀ is the height when every input is 0, so it means nothing when that is outside the data, like age 0.
3. Putting in categories: columns marked 0 and 1 (dummy variables)
Values that are not numbers, like age group, sex or treatment group, go in as columns marked 0 and 1 (dummy variables). With k groups you need k − 1 columns, and the one group without a column becomes the baseline group (reference category).
| Age group | [50s] column | [70s] column |
|---|---|---|
| 30s (baseline) | 0 | 0 |
| 50s | 1 | 0 |
| 70s | 0 | 1 |
b₂ is "how much higher the 50s are than the 30s (baseline) on average, at the same number of cups", and b₃ is the gap between the 70s and the 30s. Each group gets a line at a different height, with the same slope b₁. If you make the 70s the baseline, the intercept and the dummy coefficients change, but the coffee coefficient and each person's guess stay the same.
If you make as many columns as groups (three), the three columns always add up to 1, which is exactly the intercept column. Then the formula cannot be pinned down (the dummy variable trap). With only groups and no continuous input, regression with dummy variables gives the same test as analysis of variance, which compares group means. If you think the coffee slope itself differs by age group, add a multiplied column such as coffee × [70s] (an interaction).
4. When inputs look too much alike (multicollinearity)
When two inputs move almost together, the data cannot tell which one made y go up. The coefficients wobble a lot from sample to sample (their standard errors grow), and can even come out with the wrong sign. This is multicollinearity. Below, we draw 30 people and fit y = x₁ + x₂ + noise, repeat that 200 times, and put one dot per b₁. The true value is b₁ = 1.
Moving the slider draws the 200 samples again with the same seed, changing only the correlation between the inputs. The up-down position only keeps dots from piling up and means nothing. Orange dots are b₁ below 0, with the sign the wrong way round.
Try this. ① Correlation 0: b₁ has a standard deviation of 0.2, and every one is above 0. ② 0.9: VIF = 5.26, √VIF = 2.29. The standard deviation is 0.44, 2.2 times that at correlation 0, and 3 have the wrong sign. ③ 0.99: VIF = 50.25, √VIF = 7.09. The standard deviation is 1.35, 6.9 times as wide, and 44 of the 200 are below 0. The spread grows by almost exactly √VIF.
The VIF (variance inflation factor) is a number for each input that says how many times larger this wobble gets.
R²ⱼ is the R² of a regression that guesses input j from the other inputs (y is not used). With two inputs, R²ⱼ is the square of their correlation coefficient. A correlation of 0.9 gives 1 ÷ (1 − 0.81) = 5.26, and 0.99 gives 50.25. The VIF is how many times the variance of the coefficient grows, so the standard error grows √VIF times. Books give different cut-offs for when it becomes a problem. Rather than cutting at one number, look at whether that coefficient's standard error and confidence interval are still usable.
Multicollinearity makes coefficients wobble, but for inputs shaped like the data it does not shake the guesses (predictions) much. When b₁ gets bigger, b₂ gets smaller and they make up for each other. It is a problem when you need to read the coefficients.
How the formula is built: VIF
Build VIF = 1 ÷ (1 − R²ⱼ) step by step with the data from lab 1 (coffee and age). Press "Next" and a piece is added to the formula above (orange background marks the new piece), with the reason below.
Dot colours are the same age groups as in lab 1. The orange vertical lines are the part of coffee that age does not explain (the residuals).
Written only as formulas, the steps above look like this. The values in brackets come from the lab 1 data.
Try this. Go through all the steps: coffee ≈ 5.45 − 0.045 × age, R²ⱼ = 0.47, 1 − R²ⱼ = 0.53, VIF = 1.87, √VIF = 1.37, and the standard error of the coffee coefficient is 0.585 × 1.37 = 0.801. Coffee and age in lab 1 overlap this much, so adding age widens the coffee coefficient's standard error 1.37 times.
Step ② is what "held fixed" means. The multiple regression b₁ is exactly the slope you get by regressing y on what is left of x₁ after taking away the part the other inputs explain (the Frisch–Waugh–Lovell theorem). "Holding age fixed" is, in the arithmetic, "taking away the part of coffee that age explains".
5. How well it fits: R² and adjusted R²
R² (coefficient of determination) is, as in simple regression, "the share of the spread in y that the formula explains".
Adding an input never lowers R². Setting the new coefficient to 0 gives the old formula back, so least squares fits at least that well. Even a column of random numbers with no relation to anything raises R² a little. That is why we also look at adjusted R², which charges for the number of inputs.
p is the number of inputs (not counting the intercept), and n − p − 1 is the residual degrees of freedom. The same thing can be written 1 − (1 − R²) × (n − 1) ÷ (n − p − 1). A useless input shrinks Σresidual² a little but also shrinks n − p − 1, so adjusted R² can go down. In lab 1, coffee alone gives R² 0.21 and adjusted R² 0.2; adding age gives 0.71 and 0.7. Age was worth putting in.
Adjusted R² is still measured on the same data the model was fitted to. How well it fits new data is checked with data held back or with cross-validation (overfitting).
6. Assumptions and residual plots
The standard errors, confidence intervals and p-values of the coefficients rest on the same assumptions as simple regression. How to check them is the same as in "Assumptions, and how to read a residual plot" in section 6 of correlation and regression.
- The relationship is straight (linearity). Each input's relationship with y is straight when the other inputs are held fixed.
- The spread is even (homoscedasticity). The residuals do not open up like a trumpet as the guess changes.
- Independence. No person appears several times, and the data is not a chain in time order.
- The residuals are roughly normal. Matters most with few points.
With several inputs, look at one residual plot with the guess across, and one for each input with that input across.
7. Easy mistakes
- "The coffee coefficient adjusted for age is significant, so coffee raises blood pressure": no. Only age, which is in the formula, was held fixed. Confounders you did not measure (exercise, smoking and so on) are still there (confounding and bias). Talking about causes needs an experiment where people are split at random.
- "The more variables, the more accurate": no. R² rises just from adding (section 5), look-alike inputs make coefficients wobble (section 4), and useless inputs give a model that fits only this data (overfitting). Putting in a value that sits between the cause and the result, or a value produced by the result, makes the coefficients worse.
- "There is a formula, so any combination can be guessed": no. Each input can be inside the data's range while the combination is almost missing from the data. For example, if there are hardly any people in their 70s who drink a lot of coffee, a guess for that combination is the same as stretching beyond the data (do not stretch the line beyond the data).
- "The bigger coefficient matters more": with different units they cannot be compared. See "Reading a coefficient" in section 2.
What to use when
| Method | Good | Bad | Use it when |
|---|---|---|---|
| Simple regression (one input) | One picture shows it, easy to read | The part from other tangled values leaks into the slope | First look at a relationship; the effect of one treatment in an experiment split at random |
| Multiple regression (several inputs) | Compares with the other measured values held fixed | Cannot stop confounders you did not measure. Look-alike inputs make coefficients wobble | Adjusting for confounding in observed data; guessing y from several inputs |
| Categories as dummy variables | Group differences and continuous inputs in one formula | Needs one column fewer than the groups, and coefficients are read against the baseline group | Sex, age group, treatment group |
| Analysis of variance | Tests differences between group means in one go | Slopes of continuous inputs need separate handling | Experiments that only compare groups |
| Logistic regression | Guesses a probability between 0 and 1 when the result is yes/no | Coefficients are log odds, not probabilities, so harder to read | Has the disease or not, buys or not |
| Drop or combine one look-alike input | Coefficients settle down | You give up on telling the two apart | The VIF is large and you need to read the coefficients |
In Python
# data: made-up data (a pandas table). Blood pressure bp, cups of coffee coffee, age age,
# exercise habit group ("none", "some", "often")
import statsmodels.formula.api as smf
model = smf.ols("bp ~ coffee + age + C(group)", data=data).fit()
print(model.summary()) # coefficients, standard errors, t, p, R², adjusted R²
# C(group): turns the groups into dummy columns. The baseline is the first group by name ("none" here)
Frequently asked questions
If a coefficient in a multiple regression is significant, is that variable a cause?
No. Multiple regression only holds fixed the variables you put in the formula. Confounders you did not measure are still there, and the cause may run the other way. To talk about causes you need an experiment where people are split at random, or a design built for that question.
Is it better to put in more variables?
No. Adding a variable never lowers R², so it only looks better. Useless variables make the coefficients wobble and give a model that fits only this data. Putting in a value that sits between the cause and the result, or a value produced by the result, makes the coefficients worse. Decide what goes in from the question and background knowledge, before looking at the data.
What do I do when the VIF is large?
If you need to read each coefficient, drop one of the look-alike inputs, replace the two with one combined value, or collect more data. If you only need guesses (predictions), it may not matter much for inputs shaped like the data. Books give different cut-offs for when it becomes a problem.
Words
| Plain words used here | Textbook term |
|---|---|
| Regression with several inputs | Multiple linear regression |
| The slope with the other inputs held fixed | Partial regression coefficient, adjusted coefficient |
| The equations that set the coefficients | Normal equations |
| A hidden value changes the coefficient / the error from leaving it out | Confounding / omitted variable bias |
| The direction flips when groups are combined | Simpson's paradox |
| Columns marked 0 and 1 | Dummy variable, indicator variable |
| The group without a column | Reference category, baseline |
| A multiplied column | Interaction term |
| Inputs that look too much alike | Multicollinearity |
| How many times the wobble grows | Variance inflation factor (VIF) |
| The slope seen through what is left after the other inputs | Frisch–Waugh–Lovell theorem |
| The share the formula explains / with a charge for the number of inputs | Coefficient of determination (R²) / adjusted R² |
| n − p − 1 | Residual degrees of freedom |
Sources
- statsmodels documentation: Linear Regression.
- Penn State STAT 501: Regression Methods (multiple regression, dummy variables, multicollinearity and VIF).