What is the mean and standard deviation of mpg of the mtcars data?
mean(mtcars$mpg)
[1] 20.09062
sd(mtcars$mpg)
[1] 6.026948
Answer: The mean of mpg of mtcars is 20.09062 and the standard deviation is 6.026948.
Is there sufficient evidence that the population mean score of the
mtcars data exceeds 19 miles per gallon?
Answer: Yes
Refer to Question 1.2, state your null and alternative hypotheses?
Answer: H_a: The population mean score of the mtcars
data exceeds 19 miles per galloon or mu> 19 miles per galloon
H_0: The population mean score of the mtcars data does not exceed 19
miles per galloon or mu <= 19 miles per galloon
t.test(mtcars$mpg, mu=19, alternative = "greater")
One Sample t-test
data: mtcars$mpg
t = 1.0237, df = 31, p-value = 0.157
alternative hypothesis: true mean is greater than 19
95 percent confidence interval:
18.28418 Inf
sample estimates:
mean of x
20.09062
Is there sufficient evidence that mean difference of miles per gallon
between automatic and manual cars differ statistically?
Answer: Yes
Refer to Question 1.4, state your null and alternative
hypotheses?
Answer: H_a: The mean difference of miles per gallon
between automatic and manual cars differ statistically
H_0: The mean difference of miles per gallon between automatic and
manual cars does not differ statistically
aggregate(mtcars$mpg, list(mtcars$am), mean)
Group.1 x
1 0 17.14737
2 1 24.39231
hey<-data.frame(mtcars$am, mtcars$mpg)
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
manual<-hey %>%
filter(mtcars.am != 0)
library(dplyr)
auto<-hey %>%
filter(mtcars.am != 1)
t.test(manual$mtcars.mpg,auto$mtcars.mpg)
Welch Two Sample t-test
data: manual$mtcars.mpg and auto$mtcars.mpg
t = 3.7671, df = 18.332, p-value = 0.001374
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
3.209684 11.280194
sample estimates:
mean of x mean of y
24.39231 17.14737