Question 1

Below you will find a list of functions and what they do. Use any number of these functions to perform a descriptive analysis of the mtcars data set.

Engines displacement

max(cars$disp)
## [1] 472
min(cars$disp)
## [1] 71.1
range(cars$disp)
## [1]  71.1 472.0
mean(cars$disp)
## [1] 230.7219
median(cars$disp)
## [1] 196.3
sd(cars$disp)
## [1] 123.9387
cor(cars$disp, cars$wt)
## [1] 0.8879799

Question 2

Use the command plot(cars[, c(___)]) to create a bunch of plots. Note that the c(___) indicates a list of the columns you wish to include. Select 4 or 5 of the most interesting values to investigate.

plot(cars[, c(1,3,4,5,6)])

Question 3

We can use the command “plot(A,B)” to make a scatterplot of column A versus column B. Do an exploratory analysis on the weight of the car versus the miles per gallon of the car. Form a hypothesis that you could test.

plot(cars$mpg, cars$wt, main = "relationship between the weight and the miles per gallon", xlab = "Miles/gallon", ylab = "Weight")

Hypothesis: weight and miles/gallon have negative correlation

Base on the the scatterplot, it seems to be the heavier cars likely use more fuel to run than the lighter cars.

Question 4

Test the hypothesis that you formed in 3. You may need to consult your instructor as to what r commands you may need.

LE <- lm(cars$wt ~ cars$mpg)
summary(LE)
## 
## Call:
## lm(formula = cars$wt ~ cars$mpg)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.6516 -0.3490 -0.1381  0.3190  1.3684 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.04726    0.30869  19.590  < 2e-16 ***
## cars$mpg    -0.14086    0.01474  -9.559 1.29e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4945 on 30 degrees of freedom
## Multiple R-squared:  0.7528, Adjusted R-squared:  0.7446 
## F-statistic: 91.38 on 1 and 30 DF,  p-value: 1.294e-10
plot(cars$mpg,cars$wt, xlab="Weight", ylab="miles/gallon", main="relationship between the weight and the miles per gallon", ylim=c(0,6), xlim=c(0,36), pch=15, col="purple")
abline(lm(cars$wt ~ cars$mpg))

With the \(R^2 = 0.7528\) There is a strong negative correlation between the weight of the cars and the miles per gallon of the cars.