
Several predictors
Covered last time:
Note
✅ Key idea from last lecture
A simple regression has one predictor and one partition of variance (regression vs. residual). Today we add more predictors — the logic barely changes, but the bookkeeping does.

The multiple linear regression model:
Note
📖 Reference
Whitlock & Schluter, Ch. 17 — Regression, and Gotelli & Ellison, A Primer of Ecological Statistics, Ch. 9 — Regression, are the core references for this lecture.
What if there’s more than one predictor (X) variable?
| Continuous X | Categorical X | |
|---|---|---|
| Continuous Y | Regression | ANOVA |
| Categorical Y | Logistic regression |
Abundance of ants can be modeled as a function of:
Instead of a line, it’s modeled with a (hyper)plane.
Used in a similar way to simple linear regression:
Crawley (2012): “Multiple regression models provide some of the most profound challenges faced by the analyst”:

\[y_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + ... + \beta_p x_{ip} + \epsilon_i\]
\[y_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + ... + \beta_p x_{ip} + \epsilon_i\]
Note
✅ Key idea — what “partial” means
The relationship between a predictor and the response while holding all other predictors constant. It tells you the isolated effect of one variable, controlling for the influence of others.
Model: ant_spp ~ elevation + latitude
Call:
lm(formula = ant_spp ~ elevation + latitude, data = ant_df)
Residuals:
Min 1Q Median 3Q Max
-6.1180 -2.3759 0.3218 1.9070 5.8369
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 98.49651 26.50701 3.716 0.00147 **
elevation -0.01226 0.00411 -2.983 0.00765 **
latitude -2.00981 0.61956 -3.244 0.00427 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.022 on 19 degrees of freedom
Multiple R-squared: 0.5543, Adjusted R-squared: 0.5074
F-statistic: 11.82 on 2 and 19 DF, p-value: 0.000463
\[y_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + ... + \beta_p x_{ip} + \epsilon_i\]
Tip
🖐 Notice
This is exactly the same “signal vs. noise” structure as a simple regression — just with more terms on the signal side.
\[y_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + ... + \beta_p x_{ip} + \epsilon_i\]
Note
✅ Key idea
You’ll never do this matrix algebra by hand — R’s lm() does it instantly. What matters is knowing what it’s minimizing.
The regression equation can be used for prediction by substituting new values for the predictor (X) variables.
Warning
⚠️ Watch out!
Extrapolating a multiple regression beyond the observed range of any predictor is riskier than in simple regression — the fitted (hyper)plane has no guarantee of being right outside the data cloud.
Variance — \(SS_{total}\) is partitioned into \(SS_{regression}\) and \(SS_{residual}\).
| Source | SS | df |
|---|---|---|
| Regression | \(\sum (y_i - \bar{y})^2\) | \(p\) |
| Residual | \(\sum (y_i - \hat{y}_i)^2\) | \(n-p-1\) |
| Total | \(\sum (y_i - \bar{y})^2\) | \(n-1\) |
SS converted to (non-additive) MS = SS/df:
| Source | SS | df | MS |
|---|---|---|---|
| Regression | \(\sum (y_i - \bar{y})^2\) | \(p\) | SS/df |
| Residual | \(\sum (y_i - \hat{y}_i)^2\) | \(n-p-1\) | SS/df |
| Total | \(\sum (y_i - \bar{y})^2\) | \(n-1\) |
Two null hypotheses are usually tested in MLR. The “basic” H₀: all partial regression slopes equal 0; β₁ = β₂ = … = βₚ = 0.
Note
📖 Reference
Gotelli & Ellison, Ch. 9, covers this F-test framework for multiple regression in detail.
Also: is any specific β = 0 (explanatory role)?
Tip
🖐 Notice
This is a preview of the model-comparison approach we’ll use throughout this lecture — fit two nested models and compare their fit.
\[F_{1,n-p} = \frac{MS_{Extra}}{Full\ MS_{Residual}}\]
Tip
🖐 Notice
R also gives you a t-test for each coefficient that answers exactly this same question — you rarely need to run the partial F-test by hand.
Explained variance (r²) is calculated the same way as for simple regression:
\[r^2 = \frac{SS_{Regression}}{SS_{Total}} = 1 - \frac{SS_{Residual}}{SS_{Total}}\]
Warning
⚠️ Watch out!

Tip
📖 AV plots in R
avPlots(model)avPlot(model, variable = "proportion_black")AV plots show the relationship between Y and X₁ after removing the linear effects of all other predictors.
Regressing Y vs. each X separately does not consider the effect of other predictors — but we want to know the shape of the relationship while holding other predictors constant.

elevation latitude ant_spp
elevation 1.0000000 0.1787454 -0.5545244
latitude 0.1787454 1.0000000 -0.5879407
ant_spp -0.5545244 -0.5879407 1.0000000
Collinearity can be detected by:
Note
✅ Key idea
A high VIF doesn’t mean your model is “wrong” — it means you can’t trust the individual partial slopes for the correlated predictors, even if the overall model fits well.
Predictors can be modeled as:
\[y_i = \beta_0 + \beta_1X_{i1} + \beta_2X_{i2} + \epsilon_i \quad \text{vs.} \quad y_i = \beta_0 + \beta_1X_{i1} + \beta_2X_{i2} + \beta_3X_{i1}X_{i2} + \epsilon_i\]
This leads to “curvature” of the regression (hyper)plane.
Tip
🖐 Notice
An interaction term is just another predictor: the product \(X_1 \times X_2\), fit with its own coefficient β₃.
Interaction terms lead to “curvature” of the regression (hyper)plane.
Adding interactions:
Warning
⚠️ Watch out!
Don’t add interaction terms just to see if they’re significant — with enough predictors, some interaction will hit p < 0.05 by chance alone.
Multiple linear regression accommodates continuous and categorical variables (gender, vegetation type, etc.). Categorical vars become “dummy vars”: number of dummy variables = number of categories − 1.
| Fertility | fert1 | fert2 |
|---|---|---|
| Low | 0 | 0 |
| Med | 1 | 0 |
| High | 0 | 1 |
Coefficients are interpreted relative to a reference condition:
| Fertility | fert1 | fert2 |
|---|---|---|
| Low | 0 | 0 |
| Med | 1 | 0 |
| High | 0 | 1 |


When you have multiple predictors (and interactions!):
Note
📖 Reference
Whitlock & Schluter, Ch. 17, covers model comparison and selection for regression.
Need to account for the increase in fit that comes just from added predictors:
\[\text{Adjusted } r^2 = 1 - \frac{SS_{Residual}/(n - (p + 1))}{SS_{Total}/(n - 1)}\] \[\text{AIC} = n[\ln(SS_{Residual})] + 2(p + 1) - n\ln(n)\]
Tip
🖐 Notice
Automated stepwise selection is convenient but controversial — it can overfit and doesn’t know which predictors make biological sense. Manual, hypothesis-driven selection is usually better for a small model.
========== FULL MODEL (Both Variables) ==========
Call:
lm(formula = ant_spp ~ elevation + latitude, data = ant_df)
Residuals:
Min 1Q Median 3Q Max
-6.1180 -2.3759 0.3218 1.9070 5.8369
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 98.49651 26.50701 3.716 0.00147 **
elevation -0.01226 0.00411 -2.983 0.00765 **
latitude -2.00981 0.61956 -3.244 0.00427 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.022 on 19 degrees of freedom
Multiple R-squared: 0.5543, Adjusted R-squared: 0.5074
F-statistic: 11.82 on 2 and 19 DF, p-value: 0.000463
========== ELEVATION ONLY MODEL ==========
Call:
lm(formula = ant_spp ~ elevation, data = ant_df)
Residuals:
Min 1Q Median 3Q Max
-4.9010 -2.6947 -0.9502 2.9657 7.6363
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 12.589088 1.385615 9.086 1.55e-08 ***
elevation -0.014641 0.004913 -2.980 0.0074 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.671 on 20 degrees of freedom
Multiple R-squared: 0.3075, Adjusted R-squared: 0.2729
F-statistic: 8.881 on 1 and 20 DF, p-value: 0.0074
========== LATITUDE ONLY MODEL ==========
Call:
lm(formula = ant_spp ~ latitude, data = ant_df)
Residuals:
Min 1Q Median 3Q Max
-6.2223 -2.1188 0.0599 2.1267 6.4990
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 109.8532 30.9803 3.546 0.00203 **
latitude -2.3401 0.7199 -3.251 0.00401 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.569 on 20 degrees of freedom
Multiple R-squared: 0.3457, Adjusted R-squared: 0.313
F-statistic: 10.57 on 1 and 20 DF, p-value: 0.004006
========== MODEL COMPARISON TABLE ==========
Model Adjusted_R2 AIC R2_vs_Full AIC_vs_Full
1 Both Variables 0.5074180 115.8646 0.0000000 0.000000
2 Elevation Only 0.2728722 123.5608 -0.2345459 7.696164
3 Latitude Only 0.3129580 122.3132 -0.1944600 6.448613
========== KEY FINDINGS ==========
Full Model AIC: 115.86 (Adjusted R^2: 0.5074)
Elevation Only AIC: 123.56 (Adjusted R^2: 0.2729)
Latitude Only AIC: 122.31 (Adjusted R^2: 0.3130)
--- Differences from Full Model ---
Removing latitude: AIC increases by 7.70, Adj R^2 decreases by -0.2345
Removing elevation: AIC increases by 6.45, Adj R^2 decreases by -0.1945
========== CONCLUSION ==========
Full model has LOWEST AIC (best fit)
Full model has HIGHEST Adjusted R^2 (explains most variance)
Removing either variable worsens model performance
Both elevation and latitude are important predictors of ant species diversity!
Usually we want to know the relative importance of predictors in explaining Y. Three general approaches:
Note
✅ Key idea
None of these three approaches is “the” right answer — each answers a slightly different question about importance.
Using F-tests (or t-tests) on partial regression slopes:
Warning
⚠️ Watch out!
A bigger F-value doesn’t automatically mean a “more important” predictor if the predictors are on very different scales.
The reduction in variation of Y due to adding predictor Xⱼ:
\[r_{X_j}^2 = \frac{SS_{Extra}}{Reduced\ SS_{Residual}}\]
Tip
🖐 Notice
This is the same \(SS_{Extra}\) logic from the partial F-test earlier — just expressed as a proportion of variance instead of an F-ratio.
Predictors on different scales cannot be directly compared — why?
Note
✅ Key idea
Standardizing puts every predictor in “SD units,” so a slope of 0.5 always means “half an SD change in Y per SD change in X” — directly comparable across predictors.
Using partial r² values — partial eta squared (pEta²):
Delta R² (semi-partial R²):
== Type II ANOVA (car package) ==
Anova Table (Type II tests)
Response: ant_spp
Sum Sq Df F value Pr(>F)
elevation 81.224 1 8.8955 0.007652 **
latitude 96.085 1 10.5231 0.004272 **
Residuals 173.487 19
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
== Coefficients Table ==
Coefficients SSR df pEta_sqr dR_sqr
elevation 81.22 1 0.3189 0.2087
latitude 96.09 1 0.3564 0.2468
Residuals 173.49 19 0.5000 0.4457
== Summary Statistics ==
SSE: 173.5
SST: 389.3
Model R^2: 0.5543