Tyler Priestley
June 7th, 2025
Simple linear regression models the relationship between a single explanatory variable \(x\) and a response variable \(y\). The model is:
\[ y = \beta_0 + \beta_1 x + \epsilon \]
Where \(\beta_0\) is the intercept, \(\beta_1\) is the slope, and \(\epsilon\) is the error term.
We’ll use the mtcars dataset to model the relationship
between horsepower (hp) and miles per gallon
(mpg).
##
## Call:
## lm(formula = mpg ~ hp, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.7121 -2.1122 -0.8854 1.5819 8.2360
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 30.09886 1.63392 18.421 < 2e-16 ***
## hp -0.06823 0.01012 -6.742 1.79e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.863 on 30 degrees of freedom
## Multiple R-squared: 0.6024, Adjusted R-squared: 0.5892
## F-statistic: 45.46 on 1 and 30 DF, p-value: 1.788e-07
## 2.5 % 97.5 %
## hp -0.08889465 -0.0475619
ggplot2 and a 3D
plotly plot.