Two Independent Sample t-Test Using R

In order to test whether the mean age of people who drank alcohol differed from that of non-drinkers, the following code was used in R:

> t.test(Age~Drink,var.equal=TRUE)

Two Sample t-test
data: Age by Drink
t= 2.4983, df=2189, p-value = 0.01255
alternative hypothesis: true differences in means is not equal to 0
95 percent confidence interval:
0.140054  1.1624532
sample estimates:
mean in group No mean in group Yes
25.54535   24.89410

Independent Sample t-test and 95% Confidence Interval for a Difference in Means

In the example above, the two means are 25.4535 and 24.89410. The difference in means = 0.65125. Notice that R gives the 95% confidence interval for the difference in the means for the two groups (0.140054, 1.1624532). The null for the difference in means is 0, and if the 95% confidence interval for the difference in means does not contain the null value, then the p-value must be < 0.05 if we are using a two-tailed test. Therefore, the observation that the 95% confidence interval does not contain the null value of 0 is consistent with the p-value= 0.01255.

Example: Long-term Developmental Outcomes in Infants with Iron Deficiency

Lozoff and colleagues compared developmental outcomes in children who had been anemic in infancy to those in children who had not been anemic. Physical and mental development were compared between children with versus without a history of iron deficiency anemia. Physical development was assessed by computing the mean gross motor composite score. Mental development was assessed by measuring mean IQ scores in each group. Statistical significance was evaluated using the two independent sample t-test. Some results are shown in the table below.

Gross Motor Verbal IQ
Children w iron deficiency (n=30)
Children w/o deficiency (n=133)
52.2 ± 13.0
58.8 ± 12.5
101.4 ± 13.2
102.9 ± 12.4
Difference in means
95% CI for difference in means
-6.6
(-11.6, -1.6)
-1.5
(-6.5, 3.5)
p-value p=0.010 p=0.556

 

The difference in means for gross motor scores was -6.5 with a 95% confidence interval from -11.6 to -1.6. The null value of 0 difference is not included inside the confidence interval, indicating that the p-value must be <0.05, and as you can see it is 0.01. However, for verbal IQ the mean difference was -1.5 with a 95% confidence interval from -6.5 to 3.5. This confidence interval does include the null value of 0, indicating that the p-value must be >0.05, and as you can see the p-value for verbal IQ is 0.556 indicating that the difference is not statistically significant.

Unequal Variance

If the sample variances do not meet the equal variance assumption, R can easily compute this using the Welch t-test by simply changing "var.equal=TRUE" to "var.equal=FALSE" as shown below.

> t.test(Age~Drink,var.equal=FALSE)