使用Spearman Rho系数比较排名

发布于 2025-02-12 10:51:10 字数 806 浏览 2 评论 0原文

我想将方法​​2、3和4的排名结果与方法1进行比较。在这方面,我想使用Spearman Rho系数。我还想知道方法2、3和4与方法1之间是否存在显着关系。

database<-structure(list( 
Method1 = c(1L, 10L, 7L, 8L, 9L, 6L, 5L, 3L, 4L, 2L), Method2 = c(1L, 
8L, 6L, 7L, 10L, 9L, 4L, 2L, 5L, 3L), Method3 = c(1L, 
10L, 7L, 8L, 9L, 6L, 4L, 2L, 3L, 5L), Method4 = c(1L, 
9L, 6L, 7L, 10L, 8L, 5L, 3L, 2L, 4L)), class = "data.frame", row.names = c(NA, 
10L))

> database
   Method1 Method2 Method3 Method4
1        1       1       1       1
2       10       8      10       9
3        7       6       7       6
4        8       7       8       7
5        9      10       9      10
6        6       9       6       8
7        5       4       4       5
8        3       2       2       3
9        4       5       3       2
10       2       3       5       4

I would like to compare the ranking results of Methods 2, 3 and 4 with Method 1. In this regard, I would like to use the Spearman Rho coefficient. I would also like to know if a significant relationship between the results of methods 2, 3 and 4 with method 1. So how to do this?

database<-structure(list( 
Method1 = c(1L, 10L, 7L, 8L, 9L, 6L, 5L, 3L, 4L, 2L), Method2 = c(1L, 
8L, 6L, 7L, 10L, 9L, 4L, 2L, 5L, 3L), Method3 = c(1L, 
10L, 7L, 8L, 9L, 6L, 4L, 2L, 3L, 5L), Method4 = c(1L, 
9L, 6L, 7L, 10L, 8L, 5L, 3L, 2L, 4L)), class = "data.frame", row.names = c(NA, 
10L))

> database
   Method1 Method2 Method3 Method4
1        1       1       1       1
2       10       8      10       9
3        7       6       7       6
4        8       7       8       7
5        9      10       9      10
6        6       9       6       8
7        5       4       4       5
8        3       2       2       3
9        4       5       3       2
10       2       3       5       4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

要走干脆点 2025-02-19 10:51:10

也许您需要这样的东西,其中使用“ spearman” 方法

library(dplyr)
database %>% 
  summarise_each(funs(cor.test(., database$Method1, method = "spearman")$estimate))

输出:

  Method1   Method2   Method3   Method4
1       1 0.8787879 0.9272727 0.9030303

for p-value:输出:输出:

library(dplyr)
database %>% 
  summarise_each(funs(cor.test(., database$Method1, method = "spearman")$p.value))

输出:

  Method1     Method2      Method3     Method4
1       0 0.001977059 0.0001301624 0.000880225

Maybe you want something like this where you extract the estimate of the cor.test using the "spearman" method:

library(dplyr)
database %>% 
  summarise_each(funs(cor.test(., database$Method1, method = "spearman")$estimate))

Output:

  Method1   Method2   Method3   Method4
1       1 0.8787879 0.9272727 0.9030303

For p-value:

library(dplyr)
database %>% 
  summarise_each(funs(cor.test(., database$Method1, method = "spearman")$p.value))

Output:

  Method1     Method2      Method3     Method4
1       0 0.001977059 0.0001301624 0.000880225
櫻之舞 2025-02-19 10:51:10

sapply在其余列上循环。

sapply(c('Method2', 'Method3', 'Method4'), \(x) 
       cor.test(database[, 1], database[, x], method='spearman')[c('estimate', 'p.value')])
#          Method2     Method3      Method4    
# estimate 0.8787879   0.9272727    0.9030303  
# p.value  0.001977059 0.0001301624 0.000880225

In an sapply loop over the remaining columns .

sapply(c('Method2', 'Method3', 'Method4'), \(x) 
       cor.test(database[, 1], database[, x], method='spearman')[c('estimate', 'p.value')])
#          Method2     Method3      Method4    
# estimate 0.8787879   0.9272727    0.9030303  
# p.value  0.001977059 0.0001301624 0.000880225
眉黛浅 2025-02-19 10:51:10

在上使用总结

library(dplyr)
database %>%
  summarise(across(Method2:Method4,  ~cor.test(., Method1, method = "spearman")$estimate))
    Method2   Method3   Method4
1 0.8787879 0.9272727 0.9030303

Using summarise with across

library(dplyr)
database %>%
  summarise(across(Method2:Method4,  ~cor.test(., Method1, method = "spearman")$estimate))
    Method2   Method3   Method4
1 0.8787879 0.9272727 0.9030303
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文