Dear Rose,
the following examples may shed light on the oddity you came across in
performing -ranksum-.
webuse fuel2,clear
ranksum mpg, by(treat)
Two-sample Wilcoxon rank-sum (Mann-Whitney) test
treat | obs rank sum expected
-------------+---------------------------------
0 | 12 128 150
1 | 12 172 150
-------------+---------------------------------
combined | 24 300 300
unadjusted variance 300.00
adjustment for ties -4.04
----------
adjusted variance 295.96
Ho: mpg(treat==0) = mpg(treat==1)
z = -1.279
Prob > |z| = 0.2010
return list
scalars:
r(N_2) = 12
r(N_1) = 12
r(Var_a) = 295.9565217391304
r(z) = -1.278817949868369
r(sum_exp) = 150
r(sum_obs) = 128
r(group1) = 0
As you can see, after -return list-, Stata consider - r(sum_obs) = 128 -.
z can be obtained via the following formula (see also: Pagano M, Gauvreau K.
Principles of Biostatistics. 2nd edition. Brooks/Cole, 2000)
di (128-150)/295.96^.5
-1.2788104
When you decide to invert the samples rank-sum:
ranksum mpg, by(treat2)
Two-sample Wilcoxon rank-sum (Mann-Whitney) test
treat2 | obs rank sum expected
-------------+---------------------------------
0 | 12 172 150
1 | 12 128 150
-------------+---------------------------------
combined | 24 300 300
unadjusted variance 300.00
adjustment for ties -4.04
----------
adjusted variance 295.96
Ho: mpg(treat2==0) = mpg(treat2==1)
z = 1.279
Prob > |z| = 0.2010
. return list
scalars:
r(N_2) = 12
r(N_1) = 12
r(Var_a) = 295.9565217391304
r(z) = 1.278817949868369
r(sum_exp) = 150
r(sum_obs) = 172
r(group1) = 0
As you can see after -return list-, Stata consider - r(sum_obs) = 172 -.
Again, z can be obtained via the following formula (see also: Pagano M,
Gauvreau K. Principles of Biostatistics. 2nd edition. Brooks/Cole, 2000)
di (172-150)/295.96^.5
1.2788104.
As Martin said, usually <the test is against a two-sided alternative, so the
sign hardly matters...>
However, your concern is probably driven by the awareness that some
textbooks on statistics report the following formula for calculating
Wilkoxon rank sum test (see again: Pagano M, Gauvreau K. Principles of
Biostatistics. 2nd edition. Brooks/Cole, 2000):
zw = (W-mw)/sw
Where the z-statistic is obtained by subtracting the mean of the ranks sum
from W (the smallest of the two rank sums)and ; in this way, as you stated
in your thread, <z statistic the result should be the same no matter which
group is compared with which group>.
HTH and Kind Regards,
Carlo
-----Messaggio originale-----
Da: [email protected]
[mailto:[email protected]] Per conto di [email protected]
Inviato: domenica 25 ottobre 2009 4.29
A: statalist
Oggetto: st: the sign of z statatistic after -ranksum-?
Dear statalists,
I use -ranksum- in the stata to do the Wilcoxon rank-sum test, which is
also known as the Mann-Whitney two-sample statistic.
My typing is as followings,
webuse fuel2,clear
ranksum mpg, by(treat) // the z statistic equals -1.279
replace treat=treat==0
ranksum mpg, by(treat) // the z statistic equals 1.279
My doubt is why the sign of z statistic is opposite. As far as I know, in
the computation of z statistic the result should be the same no matter which
group is compared with which group.
Any help will be appreciated!
Best regards,
Rose.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/