首页 > 解决方案 > 如何对多项式样本进行 Tukey 风格比例检验?

问题描述

我有一张 4 x 4 的桌子。行对应于人员组,列是他们的决策类型。表中的 ij 是具有决策类型 j 的类型 i 的人数。

                  decision 1  decision 2   decision 3   decision 4
people type 1      150          50            130          270       
people type 2      540          60            160          240
people type 3      530          70            170          230
people type 4      540          40            150          270

我想做一个 Tukey 风格的比例测试来比较人的类型对。预期的输出必须类似于下表。

                     p_value  
people type 1 & 2       X         
people type 1 & 3       X        
people type 1 & 4       X          
people type 2 & 3       X          
people type 2 & 4       X          
people type 3 & 4       X          

标签: pythonrhypothesis-testpairwise

解决方案


好吧,由于没有任何名称为“Tukey 风格比例测试”,我只能假设您的意思是您想要调整 p 值,因为您在进行重大总体发现后进行多重比较。

rcompanion软件包具有允许您执行此操作并选择使用哪种常用r调整方法的功能。我的示例使用holm

Input =("
People            'decision 1'  'decision 2'   'decision 3'   'decision 4'
'people type 1'      150          50            130          270       
'people type 2'      540          60            160          240
'people type 3'      530          70            170          230
'people type 4'      540          40            150          270")

your_data = as.matrix(read.table(textConnection(Input),
                              header=TRUE,
                              row.names=1))

your_data
#>               decision.1 decision.2 decision.3 decision.4
#> people type 1        150         50        130        270
#> people type 2        540         60        160        240
#> people type 3        530         70        170        230
#> people type 4        540         40        150        270

chisq.test(your_data)
#> 
#>  Pearson's Chi-squared test
#> 
#> data:  your_data
#> X-squared = 185.06, df = 9, p-value < 2.2e-16

library(rcompanion)

pairwiseNominalIndependence(your_data,
                            fisher = FALSE,
                            gtest  = FALSE,
                            chisq  = TRUE,
                            method = "holm")
#>                      Comparison  p.Chisq p.adj.Chisq
#> 1 people type 1 : people type 2 5.44e-29    3.26e-28
#> 2 people type 1 : people type 3 1.56e-28    7.80e-28
#> 3 people type 1 : people type 4 3.02e-28    1.21e-27
#> 4 people type 2 : people type 3 7.11e-01    7.11e-01
#> 5 people type 2 : people type 4 1.07e-01    2.14e-01
#> 6 people type 3 : people type 4 5.27e-03    1.58e-02

推荐阅读