🔢 Module 4: Multiple Regression

Using multiple predictors to explain your outcome

Working guidelines

Learning Objectives

From Simple to Multiple Regression

Simple Regression (one predictor):

Y = a + b₁X₁

Example: Exam Score = 50 + 5 × Study Hours

Multiple Regression (multiple predictors):

Y = a + b₁X₁ + b₂X₂ + b₃X₃ + ...

Example: Exam Score = 40 + 4 × Study Hours + 2 × Sleep Hours - 3 × Anxiety

Why use multiple predictors?
  • Real phenomena have multiple causes
  • Control for confounding variables
  • Improve prediction accuracy
  • Understand unique contribution of each predictor

Demo 1: Adding Predictors

Open Posit Cloud. Everything in this module runs on one real dataset — 100 students, their weekly study hours, sleep, test anxiety, and exam score.

Run this:

exam <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/regression_exam_scores.csv") str(exam) # one predictor one <- lm(score ~ hours, data = exam) summary(one) # three predictors three <- lm(score ~ hours + sleep + anxiety, data = exam) summary(three)

What R gives for R-squared:

hours only R-squared = 0.4298 Adjusted R-squared = 0.4240 hours + sleep + anxiety R-squared = 0.6839 Adjusted R-squared = 0.6740

Question 1a: R² went from .43 to .68. Does that prove sleep and anxiety cause exam scores? Why or why not?

Question 1: Why did R² increase when we added the second predictor?

Interpreting Coefficients in Multiple Regression

KEY CONCEPT: Each coefficient represents the effect of that predictor while holding all other predictors constant.

Score = 40 + 4(Hours) + 2(Sleep)
Coefficient Interpretation
b₁ = 4 For each additional study hour, score increases by 4 points, holding sleep constant
b₂ = 2 For each additional sleep hour, score increases by 2 points, holding study time constant
Common mistake: Forgetting "holding other variables constant"
Wrong: "Each study hour adds 4 points"
Right: "Each study hour adds 4 points, when sleep is held constant"

R² vs. Adjusted R²

Problem with R²: It ALWAYS increases when you add predictors, even if they're useless!

Measure What it does When to use
R² % variance explained Describing current model fit
Adjusted R² R² penalized for # of predictors Comparing models with different # of predictors
Key insight: Adjusted R² can actually DECREASE when you add unhelpful predictors. This helps prevent overfitting!

Demo 2: R² vs. Adjusted R²

The dataset contains a column called shoe_size. It has nothing to do with exam performance. Add it anyway and watch what each measure does.

Run this:

silly <- lm(score ~ hours + sleep + anxiety + shoe_size, data = exam) summary(silly)

What R gives:

R-squared Adjusted R-squared hours + sleep + anxiety 0.6839 0.6740 + shoe_size 0.6850 0.6718 shoe_size coefficient: p = 0.5647

This is the whole point of adjusted R². Plain R² went up — it always does, for any predictor, however useless. Adjusted R² went down, because the tiny gain did not pay for the degree of freedom it cost.

Question 1b: A classmate reports "adding shoe size improved my model, R² went from .684 to .685." What has gone wrong in that sentence?

Multicollinearity

What it is: When predictors are highly correlated with each other.

Example of Multicollinearity:

Predicting weight from both height in inches AND height in centimeters

→ These are perfectly correlated! They measure the same thing.

Problems caused by multicollinearity:
  • Unstable coefficient estimates
  • Large standard errors
  • Coefficients may have wrong signs
  • Hard to determine individual predictor importance
How to detect:
  • Check correlations between predictors (r > 0.80 is concerning)
  • Variance Inflation Factor (VIF > 10 is problematic)
  • Large changes in coefficients when adding/removing predictors
Solutions:
  • Remove one of the correlated predictors
  • Combine correlated predictors (e.g., create an average)
  • Use different analysis method (e.g., principal components)

Demo 3: Effects of Multicollinearity

The dataset also has hours_reported — each student's own estimate of their study hours. It measures nearly the same thing as hours (r = .98). Put both in the model.

Run this:

cor(exam$hours, exam$hours_reported) both <- lm(score ~ hours + hours_reported + sleep + anxiety, data = exam) summary(both) library(car) # Chapter 24 vif(both) vif(three) # for comparison

What R gives:

> cor(exam$hours, exam$hours_reported) [1] 0.9803 Coefficients for `hours`: in `three` (hours alone) 2.4900 SE 0.2185 t = 11.397 p < 2e-16 in `both` (with hours_reported) 2.3520 SE 1.1165 t = 2.107 p = 0.0378 > vif(both) hours hours_reported sleep anxiety 25.851 25.852 1.055 1.046 > vif(three) hours sleep anxiety 1.000 1.045 1.045

Read the standard error, not the estimate. The coefficient for hours barely moved (2.49 → 2.35). Its standard error grew five times, and a predictor that was the strongest thing in the model dropped to p = .04. Nothing about study hours changed — the model simply cannot tell the two versions of it apart.

Question 2: Why is multicollinearity a problem for interpretation?

Question 2b: The VIF for hours is 25.9 with hours_reported in the model and 1.0 without it. What would you actually do about this, and what would you lose?

Question 2: Why is multicollinearity a problem for interpretation?

Interaction Effects

What it is: When the effect of one predictor depends on the level of another predictor.

Example:

Without interaction: Caffeine always improves performance by the same amount

With interaction: Caffeine helps when you're tired but doesn't help when you're already alert

Y = a + b₁X₁ + b₂X₂ + b₃(X₁ × X₂)

The b₃(X₁ × X₂) term captures the interaction

Scenario Model Needed
Caffeine and sleep have separate effects Main effects only (no interaction)
Caffeine's effect depends on sleep level Include interaction term

Demo 4: Testing for an Interaction

Does the benefit of studying depend on how anxious you are? That is an interaction question, and you can test it directly.

Run this:

inter <- lm(score ~ hours * anxiety, data = exam) summary(inter)

What R gives:

Estimate Std. Error t value Pr(>|t|) (Intercept) 42.9459 4.8260 8.899 < 2e-16 *** hours 2.6158 0.4956 5.278 8.05e-07 *** anxiety -2.2715 0.8325 -2.729 0.0076 ** hours:anxiety -0.0249 0.0841 -0.296 0.7679

There is no interaction here (p = .77), and that is worth sitting with. hours * anxiety fits without complaint, produces a coefficient, and means nothing. Being able to fit a term is not evidence the term is real — you have to look at whether it earned its place.

Note also what the main effects mean once an interaction is in the model: hours = 2.62 is now the effect of study hours when anxiety = 0, not the average effect. That is why you do not interpret main effects the usual way alongside an interaction.

Question 3a: The interaction is non-significant. Write the sentence you would put in a results section — and say what you would not be entitled to claim.

Model Selection: Which Predictors to Include?

Guidelines:
  • Theory first: Include predictors based on theory/prior research
  • Parsimony: Simpler models are better (don't overfit)
  • Statistical significance: Consider p-values for predictors
  • Adjusted R²: Compare models using this, not regular R²
  • Practical significance: Does it matter in the real world?
Avoid:
  • Including too many predictors (overfitting)
  • Automated stepwise selection without thought
  • Adding predictors just to increase R²
  • Ignoring multicollinearity

Model Comparison Example:

Model Predictors R² Adj R² Assessment
1 Study hours 0.50 0.48 Good baseline
2 Study + Sleep 0.62 0.59 Improvement!
3 Study + Sleep + Breakfast 0.63 0.58 Adj R² dropped - not helpful

Demo 5: Comparing Nested Models Properly

Comparing R² by eye is not a test. anova() on two nested models is.

Run this:

anova(one, three)

What R gives:

Analysis of Variance Table Model 1: score ~ hours Model 2: score ~ hours + sleep + anxiety Res.Df RSS Df Sum of Sq F Pr(>F) 1 98 12724.8 2 96 7053.8 2 5671 38.59 5.024e-13 ***

Adding sleep and anxiety together explains significantly more variance than study hours alone, F(2, 96) = 38.59, p < .001. This only works for nested models — every predictor in the smaller model must also be in the larger one.

Question 3b: Could you use anova() to compare score ~ hours + sleep against score ~ anxiety + shoe_size? Why or why not?

Reading Multiple Regression Output in R

This is summary(three) in full — the same model you fitted in Demo 1, printed exactly as R prints it.

Call: lm(formula = score ~ hours + sleep + anxiety, data = exam) Residuals: Min 1Q Median 3Q Max -21.837 -5.014 -0.303 6.423 20.354 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 29.5295 5.9752 4.942 3.27e-06 *** hours 2.4900 0.2185 11.397 < 2e-16 *** sleep 2.0282 0.7505 2.703 0.00814 ** anxiety -2.3287 0.3057 -7.616 1.83e-11 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 8.572 on 96 degrees of freedom Multiple R-squared: 0.6839, Adjusted R-squared: 0.674 F-statistic: 69.24 on 3 and 96 DF, p-value: < 2.2e-16

How to interpret:

Question 4: Three quick reads straight off the output.

(a) A student studies one hour more per week. How many more points, and what has to be held constant for that to be true?
(b) Where does the 96 come from?
(c) The residual standard error is 8.572 points. Is this model precise enough to predict an individual student's grade to within a letter?

Key Takeaways

Remember:
  • Each coefficient is interpreted "holding other variables constant"
  • Use Adjusted R² to compare models with different predictors
  • Check for multicollinearity - highly correlated predictors cause problems
  • Interactions mean one predictor's effect depends on another
  • Simpler models are often better (avoid overfitting)
  • Theory and logic should guide predictor selection
  • Multiple regression helps control for confounds

Congratulations!

You have completed all four modules on linear regression!

You now understand:

  1. ✓ When and why to use regression
  2. ✓ How to fit and interpret simple regression
  3. ✓ How to check assumptions and diagnose problems
  4. ✓ How to use multiple predictors effectively

Before you submit

Grading: Credit/no-credit, not scored for correctness — but credit requires a genuine attempt; blank or clearly-unattempted answers earn no credit. Work through it with your partner and say what you actually think; a wrong idea you reasoned your way to is worth more here than a right one you copied.

How to submit

  1. Click Save progress.
  2. Print: Ctrl+P (Windows) or Cmd+P (Mac).
  3. Choose "Save as PDF".
  4. Save as reg4_lastname1_lastname2.pdf and upload to the course site.