R-Wilcoxon符号秩检验

gg0vcinb  于 2023-05-20  发布在  其他
关注(0)|答案(1)|浏览(164)

Wilcoxon signed-ranks test with R vs by handMultiple Wilcoxon Signed Rank test in RWilcoxon signed rank test for heavily tied data
我有两个数据集,我正在根据通过亲和矩阵和简单比率指数计算的特定权重创建物种之间的成对关联。我想测试测试组之间的重量是否不同。这是我尝试过的,但我没有得到实际的输出。任何建议都非常感谢!
数据集1

dat1 <- structure(list(5, FALSE, c(1, 3, 4, 2, 3, 4, 3, 4, 4), c(0, 0, 
0, 1, 1, 1, 2, 2, 3), c(0, 3, 1, 4, 6, 2, 5, 7, 8), c(0, 1, 2, 
3, 4, 5, 6, 7, 8), c(0, 0, 1, 2, 5, 9), c(0, 3, 6, 8, 9, 9), 
    list(c(1, 0, 1), structure(list(), names = character(0)), 
        list(name = c("BABO", "BW", "MANG", "RC", "SKS"), n_obs = c(219L, 
        1377L, 197L, 1881L, 1232L), n_grps = c(34L, 535L, 61L, 
        665L, 339L)), list(weight = c(0.227890554864407, 0.291851490123247, 
        0.222986891666136, 0.273019105913787, 0.270047304490458, 
        0.308713136488867, 0.31127336565632, 0.313224653422152, 
        0.270579464114338))), <environment>), class = c("tbl_graph", 
"igraph"), active = "nodes")

数据集2

dat2 <- structure(list(5, FALSE, c(4, 3, 3, 4, 4), c(0, 1, 2, 2, 3), 
    c(1, 2, 0, 3, 4), c(0, 1, 2, 3, 4), c(0, 0, 0, 0, 2, 5), 
    c(0, 1, 2, 4, 5, 5), list(c(1, 0, 1), structure(list(), names = character(0)), 
        list(name = c("BABO", "BW", "MANG", "RC", "SKS"), n_obs = c(23L, 
        8L, 117L, 29L, 668L), n_grps = c(2L, 6L, 21L, 10L, 25L
        )), list(weight = c(0.282369461120595, 0.321658527239868, 
        0.307638016777122, 0.322400613641658, 0.342550960146532
        ))), <environment>), class = c("tbl_graph", "igraph"), active = "nodes")
pairwise.wilcox.test(dat1$weight, dat2$weight) -> wilcox.test

我的代码运行,但没有输出。

rryofs0p

rryofs0p1#

示例中的数据采用igraph / tbl_graph格式。这个数据结构很复杂,但是你可以提取权重来比较它们,例如:

library(tidyverse)
library(tidygraph)
#> 
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#> 
#>     filter

dat1 <- structure(list(5, FALSE, c(1, 3, 4, 2, 3, 4, 3, 4, 4), c(0, 0, 
                                                                 0, 1, 1, 1, 2, 2, 3), c(0, 3, 1, 4, 6, 2, 5, 7, 8), c(0, 1, 2, 
                                                                                                                       3, 4, 5, 6, 7, 8), c(0, 0, 1, 2, 5, 9), c(0, 3, 6, 8, 9, 9), 
                       list(c(1, 0, 1), structure(list(), names = character(0)), 
                            list(name = c("BABO", "BW", "MANG", "RC", "SKS"), n_obs = c(219L, 
                                                                                        1377L, 197L, 1881L, 1232L), n_grps = c(34L, 535L, 61L, 
                                                                                                                               665L, 339L)), list(weight = c(0.227890554864407, 0.291851490123247, 
                                                                                                                                                             0.222986891666136, 0.273019105913787, 0.270047304490458, 
                                                                                                                                                             0.308713136488867, 0.31127336565632, 0.313224653422152, 
                                                                                                                                                             0.270579464114338))), "<environment>"), class = c("tbl_graph", 
                                                                                                                                                                                                             "igraph"), active = "nodes")

dat2 <- structure(list(5, FALSE, c(4, 3, 3, 4, 4), c(0, 1, 2, 2, 3), 
                       c(1, 2, 0, 3, 4), c(0, 1, 2, 3, 4), c(0, 0, 0, 0, 2, 5), 
                       c(0, 1, 2, 4, 5, 5), list(c(1, 0, 1), structure(list(), names = character(0)), 
                                                 list(name = c("BABO", "BW", "MANG", "RC", "SKS"), n_obs = c(23L, 
                                                                                                             8L, 117L, 29L, 668L), n_grps = c(2L, 6L, 21L, 10L, 25L
                                                                                                             )), list(weight = c(0.282369461120595, 0.321658527239868, 
                                                                                                                                 0.307638016777122, 0.322400613641658, 0.342550960146532
                                                                                                             ))), "<environment>"), class = c("tbl_graph", "igraph"), active = "nodes")

str(dat1)
#> Classes 'tbl_graph', 'igraph'  hidden list of 10
#>  $ : num 5
#>  $ : logi FALSE
#>  $ : num [1:9] 1 3 4 2 3 4 3 4 4
#>  $ : num [1:9] 0 0 0 1 1 1 2 2 3
#>  $ : num [1:9] 0 3 1 4 6 2 5 7 8
#>  $ : num [1:9] 0 1 2 3 4 5 6 7 8
#>  $ : num [1:6] 0 0 1 2 5 9
#>  $ : num [1:6] 0 3 6 8 9 9
#>  $ :List of 4
#>   ..$ : num [1:3] 1 0 1
#>   ..$ : Named list()
#>   ..$ :List of 3
#>   .. ..$ name  : chr [1:5] "BABO" "BW" "MANG" "RC" ...
#>   .. ..$ n_obs : int [1:5] 219 1377 197 1881 1232
#>   .. ..$ n_grps: int [1:5] 34 535 61 665 339
#>   ..$ :List of 1
#>   .. ..$ weight: num [1:9] 0.228 0.292 0.223 0.273 0.27 ...
#>  $ : chr "<environment>"
#>  - attr(*, "active")= chr "nodes"

dat1_df <- as_tibble(dat1[2])
dat2_df <- as_tibble(dat2[2])

pairwise.wilcox.test(dat1_df$value, dat2_df$value) -> wilcox.results
wilcox.results
#> 
#>  Pairwise comparisons using Wilcoxon rank sum exact test 
#> 
#> data:  dat1_df$value and dat2_df$value 
#> 
#>                   0
#> 0.321658527239868 1
#> 
#> P value adjustment method: holm

创建于2023-05-12带有reprex v2.0.2

相关问题