上完 Basic Statistics 趁熱打鐵把 Inferential Statistics 也學(xué)習(xí)了。和上期一樣把一些遇到的問(wèn)題記錄一下。
Inferential Statistics 是在 Coursera - Methods and Statistics in Social Sciences Specialization - University of Amsterdam 里接著 Basic Statistics 的一門課程,這門課我打四星,難度加大也更深入。老師講得沒(méi)有 Basic Statistics 細(xì)致,有些地方需要自己另外找資料弄明白。而且視頻總是字幕和圖像對(duì)不上,只能當(dāng)練聽(tīng)力了。
Wilcoxon 秩和檢驗(yàn) - test statistic in R
Quiz 6 里有一題是這樣的

求
- sum of ranks in Wayne group
- sum of ranks in Astrophysics group
- test statistic in Wilcoxon rank sum test.
第一第二個(gè)問(wèn)題可以手算
rank sum Wayne = 19
rank sum Astrophysics = 17
理論上來(lái)說(shuō)當(dāng)每組樣本量相同時(shí), test statistic 為二者中較小的一個(gè),也就是17. 然后我就發(fā)現(xiàn)用R計(jì)算的W值并非 test statistic.
代碼如下:
rating <- c(2.5, 7.4, 7.2, 6.5, 8.0, 5.5, 3.2, 6.2)
group <- c('wayne', 'wayne', 'wayne', 'wayne', 'astro', 'astro', 'astro', 'astro')
wilcox.test(rating ~ group)
輸出結(jié)果為
Wilcoxon rank sum test
data: rating by group
W = 7, p-value = 0.8857
alternative hypothesis: true location shift is not equal to 0
其中W代表的是什么呢?
四處搜了一下,在這個(gè)論壇里找到解釋
Wilcoxon秩-和檢驗(yàn)結(jié)果的解讀中遇到問(wèn)題
這里的W是W統(tǒng)計(jì)量:第1組的秩和減去第1組秩和的數(shù)學(xué)期望值 n * (n+1)/2.
在R環(huán)境中,W = R - n * (n+1)/2.
所以本題中 W = 17 - 4 * (4+1)/2 = 7. test statistic = 17 并非7.
當(dāng)然我覺(jué)得這個(gè)題目有點(diǎn)tricky, 因?yàn)樵诼萏啬酻檢驗(yàn)中剛剛代碼里輸出的 W 值就是 U 值(Wilcoxon-Mann-Whitney as an alternative to the t-test)。
這兩個(gè)檢驗(yàn)方式的關(guān)系是:
Wilcoxon rank sum test = Mann Whitney U test
在 R 里面 U 檢驗(yàn)也是用的 wilcox.test(...) 的語(yǔ)句,和Wilcoxon 符號(hào)檢驗(yàn)的函數(shù)是一樣的,只是參數(shù)不太一樣(Is the W statistic output by wilcox.test() in R the same as the U statistic?)。
wilcox.test(var1, var2, paired=TRUE) # signed rank test
wilcox.test(var1 ~ var2, paired=FALSE) # Mann Whitney U test