Skip to main content

Multiple Regression

Regression with several predictors

Full model, collinearity (VIF), comparing nested models, and Type II tests on Loyn’s forest bird data from lecture.
Author

Bill Perry

📥 Download the R script 📊 Download the data

What multiple regression does

Multiple regression predicts one response from several predictors at once. Each slope is a partial slope: the effect of that predictor while holding the others constant.

\[Y = \beta_0 + \beta_1 X_1 + \beta_2 X_2 + \dots + \varepsilon\]

Data: forest bird abundance in 56 forest patches in Victoria, Australia (Loyn 1987), with patch area, distance to the nearest patch and to the nearest larger patch, year isolated, grazing intensity (1–5), and altitude.

Assumptions: the same as simple regression (linearity, normal residuals, equal variance, independence), plus predictors that are not too strongly correlated with each other (collinearity).

Step 1: Load packages and data

Area and distances are strongly right-skewed, so we log-transform them, as in lecture.

library(tidyverse)
library(car)   # vif(), Anova()

bird_df <- read_csv("data/loyn_birds.csv") %>%
  mutate(log_area        = log10(area_ha),
         log_dist        = log10(dist_m),
         log_dist_larger = log10(dist_larger_m))

glimpse(bird_df)
Rows: 56
Columns: 11
$ abundance       <dbl> 5.3, 2.0, 1.5, 17.1, 13.8, 14.1, 3.8, 2.2, 3.3, 3.0, 2…
$ area_ha         <dbl> 0.1, 0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0,…
$ year_isolated   <dbl> 1968, 1920, 1900, 1966, 1918, 1965, 1955, 1920, 1965, …
$ dist_m          <dbl> 39, 234, 104, 66, 246, 234, 467, 284, 156, 311, 66, 93…
$ dist_larger_m   <dbl> 39, 234, 311, 66, 246, 285, 467, 1829, 156, 571, 332, …
$ grazing         <dbl> 2, 5, 5, 3, 5, 3, 5, 5, 4, 5, 3, 5, 2, 1, 5, 5, 3, 3, …
$ altitude_m      <dbl> 160, 60, 140, 160, 140, 130, 90, 60, 130, 130, 210, 16…
$ grazing_class   <chr> "light", "intense", "intense", "moderate", "intense", …
$ log_area        <dbl> -1.0000000, -0.3010300, -0.3010300, 0.0000000, 0.00000…
$ log_dist        <dbl> 1.591065, 2.369216, 2.017033, 1.819544, 2.390935, 2.36…
$ log_dist_larger <dbl> 1.591065, 2.369216, 2.492760, 1.819544, 2.390935, 2.45…

Step 2: Look at the predictors together

A scatterplot matrix shows each predictor against the response and against each other.

bird_df %>%
  select(abundance, log_area, log_dist, log_dist_larger,
         year_isolated, grazing, altitude_m) %>%
  pairs()

Step 3: Fit the full model

full_model <- lm(abundance ~ log_area + log_dist +
                   log_dist_larger + year_isolated +
                   grazing + altitude_m,
                 data = bird_df)

summary(full_model)

Call:
lm(formula = abundance ~ log_area + log_dist + log_dist_larger + 
    year_isolated + grazing + altitude_m, data = bird_df)

Residuals:
     Min       1Q   Median       3Q      Max 
-15.6506  -2.9390   0.5289   2.5353  15.2842 

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)    
(Intercept)     -125.69725   91.69228  -1.371   0.1767    
log_area           7.47023    1.46489   5.099 5.49e-06 ***
log_dist          -0.90696    2.67572  -0.339   0.7361    
log_dist_larger   -0.64842    2.12270  -0.305   0.7613    
year_isolated      0.07387    0.04520   1.634   0.1086    
grazing           -1.66774    0.92993  -1.793   0.0791 .  
altitude_m         0.01951    0.02396   0.814   0.4195    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 6.384 on 49 degrees of freedom
Multiple R-squared:  0.6849,    Adjusted R-squared:  0.6464 
F-statistic: 17.75 on 6 and 49 DF,  p-value: 8.443e-11

Only log_area is clearly significant here; grazing is close.

Step 4: Check collinearity

The variance inflation factor (VIF) says how much each slope’s variance is inflated by correlation with the other predictors. VIF > 5 is a warning; > 10 is a problem.

vif(full_model)
       log_area        log_dist log_dist_larger   year_isolated         grazing 
       1.911514        1.654553        2.009749        1.804769        2.524814 
     altitude_m 
       1.467937 

All VIFs are below 3, so collinearity is not a concern here.

Step 5: Compare the full model with a reduced model

Drop the predictors that add nothing and test whether the fit got worse. This is a partial F-test of nested models.

reduced_model <- lm(abundance ~ log_area + grazing, data = bird_df)

anova(reduced_model, full_model)
Analysis of Variance Table

Model 1: abundance ~ log_area + grazing
Model 2: abundance ~ log_area + log_dist + log_dist_larger + year_isolated + 
    grazing + altitude_m
  Res.Df    RSS Df Sum of Sq     F Pr(>F)
1     53 2200.9                          
2     49 1996.8  4    204.09 1.252 0.3015

p > 0.05: the four extra predictors did not significantly improve the fit, so keep the simpler model.

Step 6: Check the assumptions on the final model

par(mfrow = c(2, 2))
plot(reduced_model)

par(mfrow = c(1, 1))

shapiro.test(residuals(reduced_model))

    Shapiro-Wilk normality test

data:  residuals(reduced_model)
W = 0.98422, p-value = 0.6728

Step 7: Test each predictor

summary() gives each partial slope. Anova(type = "II") tests each predictor after the other, which is the standard table for multiple regression.

summary(reduced_model)

Call:
lm(formula = abundance ~ log_area + grazing, data = bird_df)

Residuals:
     Min       1Q   Median       3Q      Max 
-13.4296  -4.3186  -0.6323   4.1273  13.0739 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  21.6029     3.0917   6.987 4.73e-09 ***
log_area      6.8901     1.2900   5.341 1.98e-06 ***
grazing      -2.8535     0.7125  -4.005 0.000195 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 6.444 on 53 degrees of freedom
Multiple R-squared:  0.6527,    Adjusted R-squared:  0.6396 
F-statistic: 49.81 on 2 and 53 DF,  p-value: 6.723e-13
Anova(reduced_model, type = "II")
Anova Table (Type II tests)

Response: abundance
          Sum Sq Df F value    Pr(>F)    
log_area  1184.6  1  28.527 1.977e-06 ***
grazing    666.0  1  16.038 0.0001946 ***
Residuals 2200.9 53                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Reading the output:

  • log_area slope: abundance rises by about 6.9 birds for each 10-fold increase in patch area, holding grazing constant.
  • grazing slope: each step up in grazing intensity lowers abundance by about 2.9 birds, holding area constant.
  • Adjusted R² (0.64) penalizes extra predictors; use it to compare models of different size.

Step 8: Write it up

red_aov <- Anova(reduced_model, type = "II")

Forest bird abundance increased with log10 patch area (F1,53 = 28.5, p < 0.001) and decreased with grazing intensity (F1,53 = 16, p < 0.001; multiple regression, R² = 0.65). Distance to other patches, year of isolation, and altitude did not improve the model (partial F-test, p = 0.3).

Report each predictor’s slope or F with df and p, the overall R², and how you chose the final model.