Module lessons (2/3)
Multiple Regression, Factors and Interactions
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 orfactor()by choosing the reference level (relevel). - Model synergistic effects with interaction terms (
x1 * x2) and preferAdjusted R²when comparing models of different complexity. - Distinguish between
interval = "confidence"(uncertainty of the expected mean) andinterval = "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
- 1Multi-variable formula syntax in R
- 2Test yourself: guided exercises
- 3Concept check
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.