下面的代码在两种方法的排名之间使用spearman的coef。为了生成排名,我为此使用了4个命令,然后具体地过滤了我用来做coef的列。斯皮尔曼的。然而,我想用比我更简单的方式来做这件事。
padr<-structure(list(Method1= c(0.343394182514031, 1, 0.860087696840587,
0.860087696840587, 0.868085451239441, 0.698055447477473, 0.43737803420133,
0.434970400304271, 0.434970400304271, 0.379233994071699), Method2 = c(1,
0.232979733215734, 0.240392548713602, 0.240392548713602, 0.213384133751235,
0.240137915565427, 0.321393780370283, 0.322481353908317, 0.322481353908317,
0.352233249467427), Method3 = c(1, 0.214432400448801, 0.214809476505306,
0.214809476505306, 0.16783443847331, 0.210797750473198, 0.293103343189013,
0.293692283587016, 0.293692283587016, 0.281085590908947), Method4 = c(0,
1, 0.875556823046433, 0.875556823046433, 0.891768819029077, 0.832271929255291,
0.741168314099481, 0.740578512687553, 0.740578512687553, 0.819053554576837
)), class = "data.frame", row.names = c("1", "2", "3", "4", "5",
"6", "7", "8", "9", "10"))
padr$RankMethod1 <- (nrow(padr) + 1) - rank(padr$`Method1`, ties.method = "last")
padr$RankMethod2 <- (nrow(padr) + 1) - rank(padr$`Method2`, ties.method = "first")
padr$RankMethod3 <- (nrow(padr) + 1) - rank(padr$`Method3`, ties.method = "first")
padr$RankMethod4 <- (nrow(padr) + 1) - rank(padr$`Method4`, ties.method = "last")
padr<-padr[,5:8]
padr %>%
summarise(across(RankMethod1:RankMethod4, ~cor.test(., RankMethod1, method = "spearman")$estimate))
RankMethod1 RankMethod2 RankMethod3 RankMethod4
1 1 -0.9515152 -0.830303 0.9272727发布于 2022-07-18 05:19:51
像这样吗?
library(dplyr)
padr %>%
transmute(across(, ~ifelse(row_number()==1 | row_number()==4,
nrow(padr)+1 - rank(., ties.method = "last"),
nrow(padr)+1 - rank(., ties.method = "first")), .names = "Rank{.col}")) %>%
summarise(across(, ~cor.test(., RankMethod1, method = "spearman")$estimate)) RankMethod1 RankMethod2 RankMethod3 RankMethod4
1 1 -0.9390244 -0.8170732 0.9268293https://stackoverflow.com/questions/73017461
复制相似问题