我想知道是否有一種方法可以將比較的邏輯矩陣轉換爲多字符比較測試中使用的字母符號。如在multcomp::cld
。來自邏輯矩陣的緊湊型字母顯示
我的數據是這樣的:
test_data <- data.frame(mean=c(1.48, 1.59, 1.81,1.94),CI_lower=c(1.29,1.38,1.54, 1.62),CI_upper=c(1.56,1.84, 2.3, 2.59))
mean CI_lower CI_upper
1 1.48 1.29 1.56
2 1.59 1.38 1.84
3 1.81 1.54 2.30
4 1.94 1.62 2.59
我所感興趣的是,上面寫着哪些條目有重疊的CI得到一個最終的結果,看起來像這樣的符號:
final <- data.frame(mean=c(1.48, 1.59, 1.81,1.94),CI_lower=c(1.29, 1.38,1.54, 1.62),CI_upper=c(1.56,1.84, 2.3, 2.59),letters = c("a","ab","ab","b"))
mean CI_lower CI_upper letters
1 1.48 1.29 1.56 a
2 1.59 1.38 1.84 ab
3 1.81 1.54 2.30 ab
4 1.94 1.62 2.59 b
我做了就這樣一個可憐的嘗試:
same <- outer(test_data$CI_lower, test_data$CI_upper,"-")
same <- same<0
same <- lower.tri(same, diag = FALSE) & same
same_ind <- which(same,arr.ind = T)
groups <- as.list(as.numeric(rep(NA,nrow(test_data))))
for(i in 1:nrow(same_ind)){
group_pos <- as.numeric(same_ind[i,])
for(i2 in group_pos){
groups[[i2]] <- c(groups[[i2]],i)
}
}
letters_notation <- sapply(groups,function(x){
x <- x[!is.na(x)]
x <- letters[x]
x <- paste0(x,collapse="")
return(x)
}
)
這將給予該:
mean CI_lower CI_upper letters
1 1.48 1.29 1.56 ab
2 1.59 1.38 1.84 acd
3 1.81 1.54 2.30 bce
4 1.94 1.62 2.59 de
有關如何做到這一點的任何想法?
不知道我理解所需的輸出 – 2014-12-04 12:40:18
我想還是這意味着什麼? 我需要的是c(「a」,「ab」,「ab」,「b」)。 這意味着前3個條目都有重疊的CI。最後3個具有重疊的配置項。雖然第一次和最後一次輸入不會影響。 – 2014-12-04 12:44:31
我有一個可能的非常有效的解決方案,但不完全是你想要的輸出,但你將能夠確定重疊的路徑,不知道是否發佈它 – 2014-12-04 13:03:59