Week4 project

Yue Wang

7/20/2021

Introduction of the dataset

The cars dataset gives the speed of cars and the distances taken to stop. The data were recorded in the 1920s.

library(datasets)
data(cars)
head(cars)
##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4
## 4     7   22
## 5     8   16
## 6     9   10

Introduction of the dataset

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

The purpose of the application

In this web application, we use the linear model to predict car stopping distance from speed. Following is how we build the model:

model1<- lm(dist~speed, data = cars)
result <- predict(model1, data1 = data.frame(cars$speed))
plot(cars$speed, cars$dist, xlab = "Speed", ylab = "Stopping Distance", pch = 16, xlim = c(4, 25), ylim = c(2, 120))
lines(cars$speed, result, col = "red", lwd = 2)

Based on this linear model, when a car speed is input, a corresponding stopping distance is predicted.