Comparing two means: Two independent samples tests
The standard test for comparing two means from independent samples is the independent samples Student t-test. This is obtained in Stata from the
ttest procedure. We will use the same example as shown on the previous pages:
ttest measure1==measure2, unpaired
The results show that we cannot reject the null hypothesis that the two means are equal, p=0.901.
When data are not normally distributed and the sample size is not large (n < 30)
Response: Wilcoxon Rank Sum Test
Ranking procedure for the Wilcoxon Rank Sum Test
- Combine the data from both groups and order the values from the lowest to the highest;
- Assign ranks to the observations. If a group of observations has the same valu, then compute the range of ranks and assign the average rank for each observation in the group.
- Separately list ranks for the first and second groups then sum them
(iii) Test Statistics: W = Sum of the ranks of the smallest group (small sample size);
(iv) Smallest group: low birth weight; w = 1.5 + 1.5 + 3.4 + 5.5 + 7.5 + 10 = 33;
The Mann-Whitney U test statistic: The rank-sum test can also be based on the statistic
where m is the sample size of the smallest group, n is the sample size of the largest group and w s the Wilcoxon test statistic. For the rank sum test, statistical software packages use u instead of w statistic.
We first have to convert the data into a slightly different format:
We undertake this test in Stata using the rank sum procedure (with the grouping variable). Stata command for Wilcoxon sum rank test:
ranksum measure, by(group)
The p-value of 0.9358 is very similar to that obtained from the t-test. We can also undertake this Mann-Whitney test (also known as the Wilcoxon 2-sample rank sum test) in Stata using the kwallis procedure (for the Kruskal-Wallis test). We will see shortly that the Kruskal-Wallis test is a test comparing several groups. However, if only two groups are entered, it provides the same result as the Mann-Whitney U-test. We first have to convert the data into a slightly different format:
kwallis obs, by (group)
It is important to understand that the Mann-Whitney test is a test of means ranks, not medians. So although we usually provide medians when describing the two groups, we are actually testing mean ranks, which is not the same thing. In fact, it is possible to get identical medians in the two groups, but a statistically significant Mann-Whitney test. We don't use mean ranks for descriptive statistics, as they are too difficult to interpret.