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
‘’’{r cars} write.csv(mtcars, file = “data/cars.csv”, row.names=FALSE) cars_data <- read.csv(file = “data/cars.csv”, header = TRUE, sep = “,”) #read file back in to use #cannot get this part to work yet, single dot works because that is current directory, #we didn’t write the file to the parent directory so “..” will not work #cars_data <- read.csv(file = “~/data/cars.csv”, header = TRUE, sep = “,”)
pairs(cars_data)
cor(cars_data\(wt, cars_data\)mpg)
require(ggplot2) ggplot(cars_data, aes(x=wt, y=mpg))+ geom_point(aes(shape=factor(am, labels = c(“Manual”,“Automatic”))))+ geom_smooth(method=lm)+scale_shape_discrete(name = “Transmission Type”) firstModel <- lm(mpg~wt, data = cars_data) #store in a variable
summary(firstModel)\(coef print(c('R-squared', round(summary(firstModel)\)r.sq,2)))
completeModel <- lm(mpg ~., data=cars_data) stepSolution <- step(completeModel, direction = “backward”) #get the best model bestModel <- stepSolution$call bestModel
finalModel <- lm(mpg~wt + factor(am) + qsec, data = cars_data) summary(finalModel)\(coef print(c('R-squared', round(summary(finalModel)\)r.sq,2)))