data("marketing", package = "datarium")
head(marketing, 4) youtube facebook newspaper sales
1 276.12 45.36 83.04 26.52
2 53.40 47.16 54.12 12.48
3 20.64 55.08 83.16 11.16
4 181.80 49.56 70.20 22.20
Model a numeric outcome from several predictors with lm(), interpret each coefficient holding the others constant, and decide which predictors actually matter — the practical way
Learn multiple linear regression in R — model a numeric outcome from several predictors with lm(). Interpret each coefficient (the effect of one predictor holding the others constant), read R² and the F-test, drop predictors that don’t contribute, and predict new values.
June 23, 2026
July 7, 2026
outcome = b0 + b1·x1 + b2·x2 + ….lm(outcome ~ x1 + x2 + x3, data = ...) and read the summary.predict() new values.Multiple linear regression extends simple linear regression to several predictors, so you can model an outcome that depends on more than one thing — and, crucially, isolate the effect of each predictor while holding the others constant.
The scenario: a company splits its advertising budget across youtube, facebook and newspaper, and wants to know which channels actually drive sales — and by how much, controlling for the others. A multiple regression answers exactly that.
We use the marketing dataset from datarium — the budget (in thousands of dollars) spent on youtube, facebook and newspaper, and the resulting sales, for 200 campaigns:
Add predictors with +. lm() fits the model; summary() reports the full output:
Call:
lm(formula = sales ~ youtube + facebook + newspaper, data = marketing)
Residuals:
Min 1Q Median 3Q Max
-10.5932 -1.0690 0.2902 1.4272 3.3951
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.526667 0.374290 9.422 <2e-16 ***
youtube 0.045765 0.001395 32.809 <2e-16 ***
facebook 0.188530 0.008611 21.893 <2e-16 ***
newspaper -0.001037 0.005871 -0.177 0.86
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.023 on 196 degrees of freedom
Multiple R-squared: 0.8972, Adjusted R-squared: 0.8956
F-statistic: 570.3 on 3 and 196 DF, p-value: < 2.2e-16
Read the summary piece by piece — every coefficient is an effect adjusted for the other predictors:
Each coefficient is a partial effect. “Holding the others constant” is what separates multiple regression from three separate simple regressions — it’s why newspaper’s apparent effect vanishes here.
A coefficient plot (estimate ± 95% CI) makes the story obvious — youtube and facebook sit clearly above zero, newspaper straddles it:
library(ggpubr)
library(broom)
data("marketing", package = "datarium")
model <- lm(sales ~ youtube + facebook + newspaper, data = marketing)
est <- tidy(model, conf.int = TRUE)
est <- est[est$term != "(Intercept)", ]
ggdotchart(est, x = "term", y = "estimate",
add = "segments", rotate = TRUE, sorting = "descending",
color = "#3a86d4", dot.size = 6,
ggtheme = theme_pubr()) +
geom_hline(yintercept = 0, linetype = "dashed", color = "grey50") +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2,
color = "#3a86d4")
confint() gives the plausible range for each coefficient. Newspaper’s interval includes 0 — the sign that it doesn’t contribute:
Newspaper is non-significant, so refit without it and compare. The adjusted R² barely changes — a simpler model that fits just as well:
[1] 0.8961505
Analysis of Variance Table
Model 1: sales ~ youtube + facebook
Model 2: sales ~ youtube + facebook + newspaper
Res.Df RSS Df Sum of Sq F Pr(>F)
1 197 801.96
2 196 801.83 1 0.12775 0.0312 0.8599
The anova() F-test comparing the two models is non-significant (p = 0.86) — keeping newspaper does not improve the fit, so the two-predictor model is preferred (simpler, same explanatory power).
Use predict() on the chosen model to estimate sales for a new budget split:
fit lwr upr
1 20.17605 19.83156 20.52055
A campaign spending 200 k$ on youtube and 40 k$ on facebook is predicted to sell ~20 units.
A multiple linear regression predicted sales from youtube, facebook and newspaper advertising budgets. The model was significant, F(3, 196) = 570, p < 0.001, explaining 90% of the variance (adjusted R² = 0.90). youtube (b = 0.046, 95% CI 0.043–0.049, p < 0.001) and facebook (b = 0.189, 95% CI 0.172–0.206, p < 0.001) were significant positive predictors; newspaper was not (p = 0.86).
The model is \(y = \beta_0 + \beta_1 x_1 + \dots + \beta_p x_p + \varepsilon\). Least squares chooses the coefficients to minimise \(\sum_i (y_i - \hat{y}_i)^2\); in matrix form \(\hat{\boldsymbol\beta} = (X^\top X)^{-1} X^\top y\). Each \(\hat{\beta}_j\) is the effect of \(x_j\) adjusted for all other predictors. Adjusted R² penalises R² for the number of predictors \(p\), \(R^2_{adj} = 1 - (1 - R^2)\dfrac{n - 1}{n - p - 1}\), so it only rises when a new predictor earns its keep.
The same assumptions as simple regression — linearity, constant residual variance, normal residuals, no influential outliers — plus no severe multicollinearity between predictors. Base R’s plot(model) gives the diagnostic plots:

See assumptions & diagnostics for how to read and fix each one, and multicollinearity & VIF for checking that predictors aren’t too correlated with each other.
Drop or add a predictor and watch the adjusted R² and coefficients change. The sandbox boots on first Run.
Ask Prova “fit a multiple regression on my data, interpret each coefficient holding the others constant, and tell me which predictors to keep” — it answers with code you can run and walks you through the output. The runtime is the judge. Ask Prova →
You interpreted a coefficient without “holding the others constant.” In multiple regression every slope is a partial effect — the change in the outcome per unit of that predictor with the other predictors fixed. It can differ in size, or even sign, from the simple-regression slope.
You compared models with R² instead of adjusted R². Plain R² never decreases when you add a predictor, so it always favours the bigger model. Use adjusted R² (or anova() / AIC) to compare — it only rewards predictors that genuinely help.
A predictor flipped sign or lost significance when you added another. That’s multicollinearity or confounding — the predictors share information. It’s expected (newspaper here); check VIF when it’s severe.
Each coefficient is the expected change in the outcome for a one-unit increase in that predictor, holding all other predictors constant. For sales ~ youtube + facebook, the youtube coefficient is the effect of youtube budget at a fixed facebook budget — a partial, adjusted effect, not the raw relationship.
R² is the share of variance explained; it always increases when you add a predictor, even a useless one. Adjusted R² penalises the number of predictors, so it only goes up when a new predictor improves the model more than chance would. Use adjusted R² to compare models of different sizes.
Start from the full model, look at each predictor’s t-test p-value, and drop non-significant ones, re-checking adjusted R² and an anova() model comparison each time. Keep predictors that are significant or that you have a substantive reason to control for. (Automated selection — stepwise, penalized — belongs to predictive modelling in the Machine Learning pillar.)
Because the predictors are correlated: once you control for one, the other’s unique contribution can shrink to nothing (newspaper here). This is the whole point of multiple regression — it shows the effect adjusted for the others. When predictors are highly correlated, check multicollinearity / VIF.
sales ~ youtube + facebook + newspaper, then sales ~ youtube + facebook. Does dropping newspaper change the adjusted R²?Fill the blank with newspaper, then refit without it. Compare the Adjusted R-squared lines. For question 2, remember that the multiple-model coefficient is the effect holding the other channels constant.
Dropping newspaper leaves adjusted R² essentially unchanged — it contributes nothing. For question 2: the multiple-regression result describes newspaper’s real contribution. Its simple-regression slope is positive only because newspaper budgets correlate with youtube/facebook spending; once you control for those channels, newspaper’s own effect is zero.
You can now run multiple linear regression in R: fit several predictors with lm(outcome ~ x1 + x2 + x3), interpret each coefficient as a partial effect holding the others constant, compare models with adjusted R² and anova(), drop predictors that don’t earn their place, and predict() new values. It’s the workhorse of applied modelling — and the base for categorical predictors, interactions, and diagnostics.
Prove you can do it. Master the whole Regression in R series — track your path, build projects, and earn a certificate.
Go Pro — unlimited Prova on your own data and a verifiable certificate that proves the skill.
from $15/mo billed yearly
✓ You're Pro — keep going. The runtime is the judge.
Get new R & Python lessons by email
Practical, reproducible, no spam. Unsubscribe anytime.
Double opt-in. We never share your email.
Every result on this page was produced by the code shown, run at build time against a pinned R environment — edit any block and Run to reproduce it yourself.
@online{2026,
author = {},
title = {Multiple {Linear} {Regression} in {R:} {Several}
{Predictors}},
date = {2026-06-23},
url = {https://www.datanovia.com/learn/biostatistics/regression/multiple-linear-regression-in-r},
langid = {en}
}