2.11 Two sample t-test

We can also conduct a two-sample t-test to determine if the mean population birthweight in boys is the same as the mean population birthweight in girls. The syntax here is slightly different as it uses R’s formula interface. A formula is indicated by the presence of a tilde (~), and the tilde is shorthand for ‘estimate’. So the formula below says estimate birthweight from sex. This is slightly counter-intuitive for the t-test but will make more sense when applied more generally later on.

We also use the var.test() command to assess whether the equality of variance assumption holds.

#--- Run the two-sample t-test
t.test(bab9$bweight ~ bab9$sex, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  bab9$bweight by bab9$sex
## t = 3, df = 600, p-value = 0.001
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   66.6 267.7
## sample estimates:
##   mean in group male mean in group female 
##                 3211                 3044
Exercise 9.4: What two means are being compared? What is the null hypothesis of this test? What is the alternative hypothesis? What do you conclude about the strength of evidence against the null hypothesis?

#--- Run an F-test for equality of variances
var.test(bab9$bweight ~ bab9$sex)
## 
##  F test to compare two variances
## 
## data:  bab9$bweight by bab9$sex
## F = 1, num df = 300, denom df = 300, p-value = 0.3
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
##  0.901 1.398
## sample estimates:
## ratio of variances 
##               1.12
Exercise 9.5: What is the null hypothesis of the test of equality of variances? What is the alternative hypothesis? What do you conclude about the strength of evidence against the null hypothesis? Was the assumption of equal variance in boys and girls reasonable?