The two sample t-test calculates a Student's t statistic and the associated probability to test whether or not the difference of the two sample means equals to
(i.e. to test whether or not their means are equal, you can just test whether or not their difference is 0,
). And the hypotheses take the form:
vs
Two Tailed
vs
Upper Tailed
vs
Lower Tailed
Consider two independent samples
and
, of size
and
drawn from two normal population with means
and
, and variances
and
respectively, we have:
,
,
,
where
and
are sample means and
and
are sample variances. Then we can compute the t test statistic by:
For equal variance is assumed, that is
:
In this case the test statistic t:
has a t-distribution with
degrees of freedom and
is the pooled variance of the two samples.
For equal variance is not assumed:
In this case the usual two sample t-statistic no longer has a t-distribution and an approximate test statistic, t'is used:
And a t-distribution with v degrees of freedom is used to approximate the distribution of t'where
Then compare the t value with the critical value and we will reject
if:
Two tailed test:
;
Upper tailed test:
;
Lower tailed test:
;
The p-value will also be compared with a user-defined significance level,
, which commonly 0.05 is used. And the null hypothesis
will be rejected if
.
The upper and lower
confident limits for mean difference
are calculated as:
For equal variance is assumed:
| Null Hypothesis | Confidence Interval |
|---|---|
|
|
|
|
|
|
For equal variance is not assumed:
| Null Hypothesis | Confidence Interval |
|---|---|
|
|
|
|
|
|
where
is the critical value of the t-distribution with v degrees of freedom.
The power of a two sample t-test is a measurement of its sensitivity. Detail algorithm about calculating power please read the help of Power and Sample Size.
The two-sample t-test is implemented with a Nag function, nag_2_sample_t_test (g07cac). Please refer to the corresponding Nag document for more details on the algorithm.