9.4 Two-Groups: Mean

To conduct a hypothesis test about the difference between two means in R, the command t.test() must be used. Consider the schools in the data set ohioschool and ohioscore. Suppose you are interested in whether large schools perform as well as small schools. The school enrollment cut-off values chosen are 1000 and 3000 for small and large schools:

ohio        = merge(ohioincome,ohioscore,by=c("irn"))
ohio_small  = subset(ohio,enrollment<1000)
ohio_large  = subset(ohio,enrollment>=3000)
t.test(ohio_small$score,ohio_large$score)
## 
##  Welch Two Sample t-test
## 
## data:  ohio_small$score and ohio_large$score
## t = 1.5676, df = 240.24, p-value = 0.1183
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.5216299  4.5874560
## sample estimates:
## mean of x mean of y 
##  89.21070  87.17778

Since the p-value is above 5%, we fail to reject the null hypothesis.