aaa0的个人博客分享 http://blog.sciencenet.cn/u/aaa0

博文

[转载]Kruskal-Wallis test/Friedman test

已有 3570 次阅读 2020-11-17 21:07 |系统分类:科研笔记|文章来源:转载

Kruskal-Wallis test/Friedman test 对于Ordinal Data的多群检测。可以用Kruskal-Wallis test或Friedman test来测中间值(median)的同一性。 ※注意,多群检验,重复做两-两之间的两群检验是不行的,原因在学习ANOVA的时候解释过了。 如果多群是独立的数据,就用Kruskal-Wallis test 如果是相关的(paired),就用Friedman test 这里的第12.5章,有个pdf文件说的比较清楚,还有例子。 The Mann-Whitney Test looks for differences in median values between two samples. Both the Kruskal-Wallis and Friedman Tests look for differences in median values between more than two samples. The Kruskal-Wallis Test is used to analyse the effects of more than two levels of just one factor on the experimental result. It is the non-parametric equivalent of the One Way ANOVA. The Friedman Test analyses the effect of two factors, and is the nonparametric equivalent of the Two Way ANOVA. 也就是说,Kruskal-Wallis Test是测试受1个因素影响的,多个样本的median的差异(独立多群)。而Friedman Test则是2个因素(paired多群?)。 这两个检测方法都是针对Ordinal Data的,比如排序啊,满足度啊之类的顺序尺度而不是实际的数值。 例子: 对医院的12名新护士的技术水准打分,得到的结果如下: ※注意,各个组的人数完全可以不等 内科 50 80 58 81 外科 67 69 72 88 眼科 54 62 75 77 请问这三个科室的护士技术水平有差异吗? 这个因为是受一个因素影响的,多群的平均值判定,而且是ordinal data,所以用Kruskal-Wallis Test。 因为是Ordinal data,所以计算方法如下: 1.先俺上述得分从小到大排列好,并列出其排名 科室 内 眼 内 眼 外 外 外 眼 眼 内 内 外 得分 50 54 58 62 67 69 72 75 77 80 81 88 名次 1 2 3 4 5 6 7 8 9 10 11 12 ※注:得分相同的名次按平均值计算,比如如果第3和第4得分相同,则第三第四名次都是(3+4)/2=3.5。 2.然后把各个科室的名次列出来,并计算其名次的和以及平均值 和 平均 内科 1 10 3 11 25 6.25 外科 5 6 7 12 30 7.5 眼科 2 4 8 9 23 5.75 然后用如下公式计算出其H值: 其中N是数据的总个数,k是群数,Ri是各个群组的名次和。上式计算得到H=0.500。 由于有3个群组,因此自由度=(3-1)=2。 计算出H值以后,在于样本数较小的情况,Hcrit可以通过查表得到。 对于样本数较大的情况(一说大于5),Hcrit可以用Χ平方代替。 当然了,这些都很麻烦,其实用R就可以简单地计算出来了。 > vx=c(50,80,58,81) > vy=c(67,69,72,88) > vz=c(54,62,75,77) > kruskal.test(x=list(vx,vy,vz)) Kruskal-Wallis rank sum test data: list(vx, vy, vz) Kruskal-Wallis chi-squared = 0.5, df = 2, p-value = 0.7788 上面是直接输入数据。当然了,输入名次也可以得到相同的结果 > vx=c(1,10,3,11) > vy=c(5,6,7,12) > vz=c(2,4,8,9) > kruskal.test(x=list(vx,vy,vz)) Kruskal-Wallis rank sum test data: list(vx, vy, vz) Kruskal-Wallis chi-squared = 0.5, df = 2, p-value = 0.7788 下面看看Friedman test 这篇文章说的似乎比较清楚,而且和Kruskal-Wallis test进行了比较。 它说Friedman test检测的是两个要素的影响。 比如:药物的浓度和时间对细菌数量的影响。 0(h) 1(h) 2(h) 3(h) … 濃度a(%) 100 90 80 73 … 濃度b(%) 100 80 70 60 … 濃度c(%) 100 60 45 34 … 这种情况就可以用Friedman test来做。 具体做法略过,可以用R的friedman.test来做。 > va=c(1.00, 0.90, 0.80, 0.73) > vb=c(1.00, 0.80, 0.70, 0.60) > vc=c(1.00, 0.60, 0.45, 0.34) > friedman.test(y=matrix(c(va,vb,vc),ncol=3)) Friedman rank sum test data: matrix(c(va, vb, vc), ncol = 3) Friedman chi-squared = 6, df = 2, p-value = 0.04979 ※当然了,直接输入数字而不是百分比也是同样的结果。 > va=c(100.0, 90.0, 80.0, 73.0) > vb=c(100.0, 80.0, 70.0, 60.0) > vc=c(100.0, 60.0, 45.0, 34.0) > friedman.test(y=matrix(c(va,vb,vc),ncol=3)) Friedman rank sum test data: matrix(c(va, vb, vc), ncol = 3) Friedman chi-squared = 6, df = 2, p-value = 0.04979 再进一步,直接输入排序,也可以得到同样的结果。 0(h) 1(h) 2(h) 3(h) … 濃度a(%) 100 90 80 73 … 2 3 5.5 6 濃度b(%) 100 80 70 60 … 2 5.5 7 9.5 濃度c(%) 100 60 45 34 … 2 9.5 10 11 > va=c(2,3,5.5,6) > vb=c(2,5.5,7,9.5) > vc=c(2,9.5,10,11) > friedman.test(y=matrix(c(va,vb,vc),ncol=3)) Friedman rank sum test data: matrix(c(va, vb, vc), ncol = 3) Friedman chi-squared = 6, df = 2, p-value = 0.04979 https://plaza.umin.ac.jp/~health-stat/wpsystem/wp-content/uploads/2017/01/chapter8_slide.pdf https://data-science.gr.jp/implementation/ist_r_kruskal_wallis_test.html https://towardsdatascience.com/what-is-a-p-value-b9e6c207247f https://towardsdatascience.com/statistical-significance-hypothesis-testing-the-normal-curve-and-p-values-93274fa32687

https://wap.sciencenet.cn/blog-252888-1258787.html

上一篇:[转载]浙大学霸逆天笔记曝光:高手都是持续性自律,废人才是间歇性自虐
收藏 IP: 96.234.183.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-24 07:43

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部