Simple regression uses one predictor. Most outcomes in medicine have many causes. Multiple regression puts several predictors into one model. Each coefficient then describes the effect of one predictor with the others held fixed.
14.1 The problem
Hypertension researchers want to know if blood pressure in infancy predicts blood pressure in adult life. The blood pressure of a newborn is hard to study, because other factors change it. Two of these factors are the baby’s birthweight and the day of life on which we measure the pressure.
Rosner (Fundamentals of Biostatistics, Cengage) gives the systolic blood pressure (SBP) of 16 newborns. For each baby we also have the birthweight in ounces and the age in days (2 to 5).
Does birthweight change a newborn’s blood pressure, once we allow for the day on which we measure it?
Show code
p_bw <-ggplot(bp_df, aes(birthweight, sbp)) +geom_smooth(method ="lm", formula = y ~ x, se =FALSE, colour ="firebrick") +geom_point(colour ="steelblue", size =2) +labs(x ="birthweight (oz)", y ="SBP (mmHg)")p_age <-ggplot(bp_df, aes(age, sbp)) +geom_smooth(method ="lm", formula = y ~ x, se =FALSE, colour ="firebrick") +geom_point(colour ="steelblue", size =2) +labs(x ="age (days)", y ="SBP (mmHg)")p_bw + p_age
Figure 14.1: Systolic blood pressure of 16 newborns (Rosner) against birthweight (left) and age in days (right). Red lines are simple least-squares fits.
We first fit birthweight alone.
fit_bw <-lm(sbp ~ birthweight, data = bp_df)coef(summary(fit_bw))
Estimate Std. Error t value Pr(>|t|)
(Intercept) 69.1333333 10.40989558 6.641117 1.112118e-05
birthweight 0.1573333 0.08555527 1.838967 8.722334e-02
The slope is 0.157 mmHg per ounce, with p = 0.087. On its own, birthweight does not reach the 5% level. Age has a strong relation with SBP, and birthweight seems to have a weak one.
14.2 Intuitive solution
Some of the scatter in the left panel of Figure 14.1 comes from age. Babies measured on day 5 have a higher SBP than babies measured on day 2, whatever their weight. This variation hides the effect of birthweight. So we remove the effect of age first.
We do this in two steps. First, we regress SBP on age and keep the residuals. This is the part of SBP that age does not explain. Second, we regress birthweight on age and keep the residuals. This is the part of birthweight that age does not explain. Then we plot one set of residuals against the other.
sbp_res <-residuals(lm(sbp ~ age, data = bp_df))bw_res <-residuals(lm(birthweight ~ age, data = bp_df))fit_av <-lm(sbp_res ~ bw_res)coef(fit_av)
(Intercept) bw_res
-2.375413e-16 1.255833e-01
Show code
lims <-range(c(bp_df$sbp -mean(bp_df$sbp), sbp_res))p_raw <-ggplot(bp_df, aes(birthweight -mean(birthweight), sbp -mean(sbp))) +geom_smooth(method ="lm", formula = y ~ x, se =FALSE, colour ="firebrick") +geom_point(colour ="steelblue", size =2) +coord_cartesian(ylim = lims) +labs(title ="before: no adjustment", x ="birthweight - mean (oz)", y ="SBP - mean (mmHg)")p_adj <-ggplot(tibble(bw_res, sbp_res), aes(bw_res, sbp_res)) +geom_smooth(method ="lm", formula = y ~ x, se =FALSE, colour ="firebrick") +geom_point(colour ="steelblue", size =2) +coord_cartesian(ylim = lims) +labs(title ="after: age removed from both", x ="birthweight, residual on age (oz)", y ="SBP, residual on age (mmHg)")p_raw + p_adj
Figure 14.2: SBP against birthweight in 16 newborns (Rosner), before (left) and after (right) we remove the effect of age from both variables. The right panel is an added-variable plot, and its scatter around the red line is much smaller.
The cloud in the right panel is much tighter. The standard deviation (SD) of SBP is 6.69 mmHg. After we remove age, the SD of what is left is 3.29 mmHg. The slope in the right panel is 0.126 mmHg per ounce. This is close to the slope without adjustment, and now the points lie close to the line. The smaller scatter gives the slope a smaller standard error.
14.3 Formal solution
14.3.1 The model
With \(k\) predictors, the multiple linear regression model is
with the same LINE assumptions as in Chapter 11. In matrix form it is \(\mathbf y = \mathbf X\boldsymbol\beta + \boldsymbol\varepsilon\). \(\mathbf X\) has \(p = k + 1\) columns: a column of 1s and one column for each predictor. Least squares again chooses the \(\boldsymbol\beta\) that makes the RSS smallest, and the solution is \(\hat{\boldsymbol\beta} = (\mathbf X^\top\mathbf X)^{-1}\mathbf X^\top\mathbf y\).
With two predictors, the model is a plane in three dimensions. Least squares chooses the plane that makes the sum of squared vertical distances from the points smallest. With more predictors, it is a hyperplane.
fit <-lm(sbp ~ age + birthweight, data = bp_df)summary(fit)
Call:
lm(formula = sbp ~ age + birthweight, data = bp_df)
Residuals:
Min 1Q Median 3Q Max
-4.0438 -1.3481 -0.2395 0.9688 6.6964
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 53.45019 4.53189 11.794 2.57e-08 ***
age 5.88772 0.68021 8.656 9.34e-07 ***
birthweight 0.12558 0.03434 3.657 0.0029 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.479 on 13 degrees of freedom
Multiple R-squared: 0.8809, Adjusted R-squared: 0.8626
F-statistic: 48.08 on 2 and 13 DF, p-value: 9.844e-07
The coefficient of birthweight is 0.126 mmHg per ounce, with p = 0.0029. It is exactly the slope of the added-variable plot, 0.126. This is a general result (the Frisch-Waugh theorem). Each coefficient in a multiple regression is the slope of \(Y\) on one predictor, after we remove the other predictors from both.
Figure 14.3: The fitted plane for the newborn data (Rosner), seen as one line for each age. The lines are parallel: the model gives the same birthweight slope at every age.
14.3.2 Partial regression coefficients
\(\beta_j\) is a partial regression coefficient. It is the mean change in \(Y\) for one unit more of \(x_j\), with all other predictors in the model held fixed. In simple regression, the slope ignores the other variables. Here, each extra day of life goes with 5.89 mmHg more SBP at a fixed birthweight. Each extra ounce of birthweight goes with 0.126 mmHg more at a fixed age.
We compare the birthweight coefficient in the two models.
The estimate moved only a little, from 0.157 to 0.126. The correlation between age and birthweight is only 0.11, so age is not a strong confounder here. The standard error changed much more, from 0.086 to 0.034.
The reason is the residual standard error. Age explains most of the variation in SBP, so the residual standard error fell from 6.21 to 2.48 mmHg. Every standard error is proportional to the residual SE. So the p-value for birthweight fell from 0.087 to 0.0029.
A variable can enter a model for two reasons. A confounder is related to both \(x\) and \(Y\), and it changes the estimate itself. A strong predictor of \(Y\) that is unrelated to \(x\) leaves the estimate almost unchanged, but it makes the estimate more precise. In the newborn data, age is the second type.
The birthwt data from Chapter 12 show the first type. The data come from 189 births at Baystate Medical Center, Massachusetts, in 1986 (Hosmer and Lemeshow, Applied Logistic Regression, Wiley). Race was recorded as white, black or other. We ask if race confounds the effect of smoking.
Smoking was common among white mothers (52 of 96) and less common among “other” mothers (12 of 67). White mothers also had the heaviest babies, with a mean of 3103 g, against 2805 g for “other” mothers. So race hides part of the harm of smoking. Without adjustment, smokers’ babies are 284 g lighter. After adjustment for race, the difference is 429 g. Here the adjustment changed the estimate itself.
14.3.3 Standardised coefficients
The two coefficients in the newborn model have different units: mmHg per day and mmHg per ounce. You cannot compare them directly. The standardised coefficient is \(\hat\beta_j \times s_{x_j}/s_y\). It is the change in \(Y\), in SDs of \(Y\), for one SD more of \(x_j\), with the other predictors held fixed.
b <-coef(fit)[-1]b *c(sd(bp_df$age), sd(bp_df$birthweight)) /sd(bp_df$sbp)
age birthweight
0.8332308 0.3520770
One SD more of age goes with 0.83 SD more SBP. One SD more of birthweight goes with 0.35 SD more. In this sample, age has the larger effect.
14.3.4 Categorical predictors and interactions
A yes/no predictor enters the model as a 0/1 indicator \(D\), as in Chapter 12. With one continuous predictor, the model \(Y = \beta_0 + \beta_1 x + \beta_2 D + \varepsilon\) gives two parallel lines. \(\beta_2\) is the vertical distance between them.
An interaction lets the slope differ between the groups:
\[
Y = \beta_0 + \beta_1 x + \beta_2 D + \beta_3\, x \cdot D + \varepsilon .
\]
The slope is \(\beta_1\) when \(D = 0\) and \(\beta_1 + \beta_3\) when \(D = 1\). The test of \(H_0: \beta_3 = 0\) asks if the effect of \(x\) is the same in both groups. In R, y ~ x + D fits parallel lines and y ~ x * D adds the interaction.
We use the birthwt data again. lwt is the mother’s weight in pounds at her last menstrual period.
fit_par <-lm(bwt ~ lwt + smoke, data = bw)fit_int <-lm(bwt ~ lwt * smoke, data = bw)coef(summary(fit_par))
Figure 14.4: Birthweight against the mother’s weight, by smoking (Hosmer and Lemeshow, MASS::birthwt). Left: the model without interaction gives parallel lines. Right: the model with interaction lets the slopes differ.
In the parallel model, smokers’ babies are 272 g lighter at any fixed maternal weight. Each extra pound of maternal weight goes with 4.2 g more birthweight. The interaction coefficient is -2.4 g per pound, with p = 0.48. The data give no evidence that the slope differs between smokers and non-smokers.
In the interaction model, the smokeyes coefficient is the difference at lwt = 0, a mother of zero weight. It has no meaning by itself. If you centre lwt first, this coefficient becomes the difference at the average maternal weight.
A factor with \(k\) levels enters as \(k - 1\) indicators. Each indicator compares one level with a reference level. R uses the first level as the reference. For race, the reference is “white”:
fit_race <-lm(bwt ~ race, data = bw)coef(fit_race)
Analysis of Variance Table
Response: bwt
Df Sum Sq Mean Sq F value Pr(>F)
race 2 5015725 2507863 4.9125 0.008336 **
Residuals 186 94953931 510505
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The two coefficients compare black and other mothers with white mothers. To test race as a whole, we must test both indicators together. The ANOVA table does this with one F-test, on 2 degrees of freedom (df). This is the one-way ANOVA of Fisher (Chapter 1), written as a regression.
14.3.5 The overall F-test
The first question for a multiple regression asks if at least one predictor is useful. The null hypothesis is
The F statistic compares the explained and the residual variation, each per degree of freedom:
\[
F = \frac{\text{ESS}/k}{\text{RSS}/(n - k - 1)} .
\]
If \(H_0\) is true, both the numerator and the denominator estimate \(\sigma^2\), and \(F\) is close to 1. If at least one predictor is useful, the numerator is larger, and so is \(F\).
Under \(H_0\) and the LINE assumptions, \(F\) has an F distribution with \(k\) and \(n - k - 1\) degrees of freedom. If \(U\) and \(V\) are independent chi-square variables with \(d_1\) and \(d_2\) degrees of freedom, then \((U/d_1)/(V/d_2)\) has the \(F(d_1, d_2)\) distribution. Fisher worked with half the logarithm of this ratio. Snedecor tabulated the ratio itself and named it F, after Fisher (Chapter 1).
y <- bp_df$sbpESS <-sum((fitted(fit) -mean(y))^2)RSS <-sum(residuals(fit)^2)k <-2F_stat <- (ESS / k) / (RSS / (n - k -1))c(F = F_stat, p =pf(F_stat, k, n - k -1, lower.tail =FALSE))
F p
4.808063e+01 9.844334e-07
For the newborn data, \(F\) = 48.08 on 2 and 13 degrees of freedom. This is the value at the bottom of summary(fit). At least one of age and birthweight is related to SBP. Chapter 15 builds the F statistic step by step, and shows why it is close to 1 when \(H_0\) is true.
14.3.6 One F-test in place of many t-tests
Each row of summary() has its own t-test. With many predictors, the t-tests together make too many false positives. Each test at the 5% level has a 5% chance to reject a true null hypothesis. With 20 useless predictors, at least one t-test is often “significant”.
We check this with simulated data. We make 1,000 data sets, each with 100 subjects and 20 predictors of pure noise. \(Y\) is also pure noise, so every null hypothesis is true.
set.seed(20)sim <-replicate(1000, { X <-matrix(rnorm(100*20), nrow =100) y <-rnorm(100) s <-summary(lm(y ~ X)) f <- s$fstatisticc(any_t =any(coef(s)[-1, 4] <0.05),F =pf(f[1], f[2], f[3], lower.tail =FALSE) <0.05)})rowMeans(sim)
any_t F.value
0.591 0.060
In 59.1% of the data sets, at least one of the 20 t-tests gave p < 0.05. The F-test rejected \(H_0\) in only 6% of them, close to the 5% that it promises. The F-test controls the error rate for the model as a whole.
14.3.7 The ANOVA table
The ANOVA table sets out the sums of squares, their degrees of freedom, and their ratio.
Source
Sum of squares
df
Mean square
F
Regression
ESS
\(k\)
ESS\(/k\)
MS\(_{\text{reg}}\)/MS\(_{\text{res}}\)
Residual
RSS
\(n - k - 1\)
RSS\(/(n-k-1)\)
Total
TSS
\(n - 1\)
R’s anova() gives a sequential table. Each row is the gain in ESS when that term is added to the terms above it. So the order of the terms changes these rows. The residual row stays the same.
anova(fit)
Analysis of Variance Table
Response: sbp
Df Sum Sq Mean Sq F value Pr(>F)
age 1 508.82 508.82 82.784 5.322e-07 ***
birthweight 1 82.22 82.22 13.377 0.002896 **
Residuals 13 79.90 6.15
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(fit_age, fit)
Analysis of Variance Table
Model 1: sbp ~ age
Model 2: sbp ~ age + birthweight
Res.Df RSS Df Sum of Sq F Pr(>F)
1 14 162.121
2 13 79.902 1 82.219 13.377 0.002896 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The second call compares two nested models: age alone, and age plus birthweight. The F statistic is 13.38. It tests if birthweight adds anything once age is in the model. For one extra coefficient, this F is the square of its t value: 3.657\(^2\) = 13.38.
The same comparison tests a factor. The F-test for race, added to a model with maternal weight and smoking, uses 2 degrees of freedom:
Analysis of Variance Table
Model 1: bwt ~ lwt + smoke
Model 2: bwt ~ lwt + smoke + race
Res.Df RSS Df Sum of Sq F Pr(>F)
1 186 93194298
2 184 85162590 2 8031708 8.6765 0.0002507 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
14.3.8 R² and adjusted R²
As in Chapter 12, \(R^2 = 1 - \text{RSS}/\text{TSS}\). In multiple regression, \(R^2\) is the squared correlation between \(Y\) and the fitted values \(\hat Y\).
The five noise columns raise \(R^2\) from 0.881 to 0.921. Adjusted \(R^2\) falls from 0.863 to 0.851. Adjusted \(R^2\) charges each coefficient one degree of freedom, so useless predictors make it smaller. Use adjusted \(R^2\) to compare models of different sizes.
With 16 babies and 7 predictors, the noisy model has only 8 residual degrees of freedom. Many predictors and few subjects give a model that fits the sample well and predicts new subjects badly. Chapter 16 and Chapter 17 return to this problem.
14.4 Summary
A partial regression coefficient is the effect of one predictor with the other predictors held fixed. It equals the slope of the added-variable plot.
Adjustment for a confounder changes an estimate. Adjustment for a strong predictor of \(Y\) that is unrelated to \(x\) makes the estimate more precise.
The overall F-test asks if any predictor is useful. It keeps the false-positive rate at 5%, which many separate t-tests do not.
The coefficient of determination \(R^2\) never decreases when you add a predictor. Adjusted \(R^2\) can decrease, so it can compare models of different sizes.