Skip to main content
Module 7 · Lesson 2 of 315/18 in the course~24 min
Module lessons (2/3)

Multiple Regression, Factors and Interactions

Lesson preview5 hands-on exercises readyCourse R · Module 7 — Regression and Linear Models

Model multiple numeric and categorical predictors (dummy encoding of factor()), x1 * x2 interactions, and intervals with predict().

What you'll learn in this lesson

  • Add multiple predictors in a formula (y ~ x1 + x2) interpreting the effects with all other variables being equal.
  • Take advantage of the automatic dummy encoding of lm() on text columns or factor() by choosing the reference level (relevel).
  • Model synergistic effects with interaction terms (x1 * x2) and prefer Adjusted R² when comparing models of different complexity.
  • Distinguish between interval = "confidence" (uncertainty of the expected mean) and interval = "prediction" (uncertainty about a new single observation).

Overview

In the real world almost no phenomenon depends on a single cause: the salary depends on both the years of experience and the role; sales depend both on the advertising budget and on any active promotions. Extending lm() to multiple variables in R requires only the symbol + inside the formula.

If you include a column character or factor (e.g. track = c("Base", "Pro")), R chooses one level as the base reference (in alphabetical order, or chosen by you with factor(..., levels = ...)), and estimates a differential coefficient for each of the other levels.

Sections covered in this lesson

  1. 1Multi-variable formula syntax in R
  2. 2Test yourself: guided exercises
  3. 3Concept check
Pro Lesson · Module 7 — Regression and Linear Models

Unlock "Multiple Regression, Factors and Interactions" and the full Course R curriculum

Model multiple numeric and categorical predictors (dummy encoding of factor()), x1 * x2 interactions, and intervals with predict().

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course R plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.