Data 605 Week 11 Assignment
Load in Packages
library(ggplot2)
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.5.3
## -- Attaching packages ------------------------------------------------------------------------------------ tidyverse 1.2.1 --
## v tibble 2.0.1 v purrr 0.2.5
## v tidyr 0.8.2 v dplyr 0.7.8
## v readr 1.3.1 v stringr 1.3.1
## v tibble 2.0.1 v forcats 0.3.0
## -- Conflicts --------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
cars <- cars
Build and Evaluate the Model
ggplot(data = cars, aes(x = speed, y = dist)) +
geom_point(color='blue') +
geom_smooth(method = "lm", se = FALSE)#+xlim(0,25000)
linear_model <- lm(dist~speed,cars)
plot(linear_model)
linear_model
##
## Call:
## lm(formula = dist ~ speed, data = cars)
##
## Coefficients:
## (Intercept) speed
## -17.579 3.932
summary(linear_model)
##
## Call:
## lm(formula = dist ~ speed, data = cars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.069 -9.525 -2.272 9.215 43.201
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -17.5791 6.7584 -2.601 0.0123 *
## speed 3.9324 0.4155 9.464 1.49e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 15.38 on 48 degrees of freedom
## Multiple R-squared: 0.6511, Adjusted R-squared: 0.6438
## F-statistic: 89.57 on 1 and 48 DF, p-value: 1.49e-12
Conclusion
The relationship between stopping distance and speed is statistically significant which makes sense because the faster a car is going the harder it is for the car to stop. Based on the mnodel for every additional mpg of speed the distance to stop but increase 3.932 units of distance. The quantile quantile plot is pretty close to a straight line meaning that the residuals are indeed appoximately distributed. The adjusted R-squared value is .64 which means that around 64% of the variance in stopping distance can be explained with just the speed of the car