When data gets larger and the relationships become more complicated it can be useful to analyze the way multiple variables changing affects an outcome. Multiple linear regression is a helpful tool when there are multiple significant variables, and can also be helpful in determining which variables are the significant ones. Here is an example of a multiple linear regression to determine miles per gallon using the cars weight, type of transmission, engine shape, and number of cylinders, gears, and carburetors.
mtcars_multi = lm(mpg ~ wt + cyl + vs + am + gear + carb, data = mtcars)
summary(mtcars_multi)
Call:
lm(formula = mpg ~ wt + cyl + vs + am + gear + carb, data = mtcars)
Residuals:
Min 1Q Median 3Q Max
-4.6224 -1.1054 -0.3032 1.5267 5.3178
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 33.7632 8.0153 4.212 0.000287 ***
wt -2.3913 1.0083 -2.372 0.025721 *
cyl -0.9629 0.7006 -1.374 0.181558
vs 0.6684 1.8410 0.363 0.719622
am 1.8291 1.8772 0.974 0.339187
gear 0.3484 1.4096 0.247 0.806809
carb -0.8326 0.5508 -1.512 0.143157
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.588 on 25 degrees of freedom
Multiple R-squared: 0.8513, Adjusted R-squared: 0.8157
F-statistic: 23.86 on 6 and 25 DF, p-value: 3.268e-09