There are two types of two-sample t-tests – (1) variances are equal and (2) variances are unequal. In our introductory statistics course we only discussed the equal variances case. In the equal variances case the degrees-of-freedom (df) are \(n_{1}+n_{2}-2\) which alwasy results in a whole number. However, the df formula for the unequal variances case is much more complicated and often results in decimal degrees-of-freedom. Thus, if you expected the two-sample t-test df to be \(n_{1}+n_{2}-2\), but they were a decimal, then you forgot to set var.equal=TRUE
in t.test()
. Of course, before doing this you should verify with levenesTest()
from car
that the variances are statistically equal (see this FAQ).
As an example, the following is the results from using t.test()
without setting var.equal=TRUE
(note that the unequal variances version is also called the Welch two-sample t-test).
> t.test(extra~group,data=sleep)
Welch Two Sample t-test with extra by group
t = -1.8608, df = 17.776, p-value = 0.07939
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-3.3654832 0.2054832
sample estimates:
mean in group 1 mean in group 2
0.75 2.33
In contrast, these are the results from using t.test()
with var.equal=TRUE
for the same data.
> t.test(extra~group,data=sleep,var.equal=TRUE)
Two Sample t-test with extra by group
t = -1.8608, df = 18, p-value = 0.07919
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-3.363874 0.203874
sample estimates:
mean in group 1 mean in group 2
0.75 2.33