[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Carlo Lazzaro" <carlo.lazzaro@tin.it> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
R: st: R: the sign of z statatistic after -ranksum-? (flag: Stata 9/2 SE) |

Date |
Sun, 25 Oct 2009 17:00:38 +0100 |

Dear Rose, The formula used in Stata (release 9/2 SE) is reported in: [R] Stata Base Reference Manual. Volume 3. R-Z. Release 9: 1-5. Kind Regards, Carlo -----Messaggio originale----- Da: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Per conto di gjhxmu@sina.com Inviato: domenica 25 ottobre 2009 15.00 A: statalist Oggetto: Re: st: R: the sign of z statatistic after -ranksum-? (flag: Stata 9/2 SE) Dear Carlo and Martin, thank you very much for your help, especially for Carlo's detailed illustration. Just as Carlo's guess, I followed the formula from textbooks as follows to get the z-statistic. Assuming the number for the two independent sample is m and n respectively. Firstly to get the U statistic, U=w-1/2*k*(k+1) // where w is the rank sum for the bigger number and k is the bigger number. If m equals n, k takes the number for the group first appearing in the rank. Then to get the Z statistic, Z=(U-1/2*m*n)/sqrt(1/12*m*n*(m+n+1)) Following the formula, I think no matter which group is compared with which group, the Z statistic is the same. I am sorry for not reading the concrete formula used in the stata. Thank you for your kind help. Best regards, Rose. ----- Original Message ----- From: Carlo Lazzaro <carlo.lazzaro@tin.it> To: <statalist@hsphsun2.harvard.edu> Subject: st: R: the sign of z statatistic after -ranksum-? (flag: Stata 9/2 SE) Date: 2009-10-25 19:18:29 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: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Per conto di gjhxmu@sina.com 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/ * * 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/

**References**:**Re: st: R: the sign of z statatistic after -ranksum-? (flag: Stata 9/2 SE)***From:*gjhxmu@sina.com

- Prev by Date:
**st: RE: AW: AW: Compute mean for groups leaving one member out** - Next by Date:
**Re: R: st: R: the sign of z statatistic after -ranksum-? (flag: Stata 9/2 SE)** - Previous by thread:
**Re: st: R: the sign of z statatistic after -ranksum-? (flag: Stata 9/2 SE)** - Next by thread:
**st:how to test the seasonal effect in monthly data and smooth that effect** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |