17.3.2.2 Algorithms (TwoSample TTest)tTestTwoSampleAlgorithm
The two sample ttest 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
Test Statistics
Consider two independent samplesand, 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 tdistribution 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 tstatistic no longer has a tdistribution and an approximate test statistic, t'is used:
And a tdistribution 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 pvalue will also be compared with a userdefined significance level,, which commonly 0.05 is used. And the null hypothesis will be rejected if .
Confidence Intervals
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 tdistribution with v degrees of freedom.
Power Analysis
The power of a two sample ttest is a measurement of its sensitivity. Detail algorithm about calculating power please read the help of Power and Sample Size.
Reference
The twosample ttest 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.
