Adding a predictor in R is literally a +. The matrix inversion you skipped by hand? R just does it.
Never used R? Set it up in 2 minutes →
The formula y ~ x1 + x2 reads "y explained by x1 and x2". Everything else is identical to SLR.
Everything from the worked example is in this one block:
| In the output | Value | Meaning |
|---|---|---|
| hr | 0.508 | +0.51 runs per HR, holding walks fixed |
| walks | 0.819 | +0.82 runs per walk, holding HR fixed |
| Adjusted R-squared | 0.9979 | fit, penalised for 2 predictors |
| F-statistic | 1165 | whole model is significant (p ≈ 0) |
lm(y ~ x1 + x2, data = d) — fit with two predictors (add more with +)summary(fit) — coefficients, adjusted R², F-statisticconfint(fit) — 95% intervals for each coefficientpredict(fit, newdata) — predict y for new x?, x₂vif(fit) — check multicollinearity (predictors too alike?) — from the car packageanova(fit1, fit2) — does an extra predictor actually help?Based on the output above. Type-and-check.

Add predictors with +.


Three letters — "variance inflation factor".

The Estimate on the walks row.
One predictor or ten, it's the same call with more +s. The hard part is interpretation — which you've now done both ways.