我的數據集包括多威爾科克斯測試與R
cb <- data.frame(group = ("A", "B", "C", "D", "E"),
WC = runif(100, 0, 100),
Ana = runif(100, 0, 100),
Clo = runif(100, 0, 100))
str(cb)
data.frame: 66936 obs of 89 variables:
$group: Factor w/ 5 levels "A", "B", "C" ...
$WC: int 19 28 35 92 10 23...
$Ana: num 17.2 48 35.4 84.2
$ Clo: num 37.2 12.1 45.4 38.9
....
現在我想在$組執行多個威爾科克斯測試,因此它看起來像這到底:
commands:
wilcox.test(cb$WC[cb$group == "A"], cb$WC[cb$group == "B"])
wilcox.test(cb$WC[cb$group == "A"], cb$WC[cb$group == "C"])
wilcox.test(cb$WC[cb$group == "A"], cb$WC[cb$group == "D"])
wilcox.test(cb$WC[cb$group == "A"], cb$WC[cb$group == "E"])
....
inserting the p-value:
WC A B C D E
A 1 0.12 0.03 0.2 0.42
B 0.12 1 0.1 0.07 0.1
C 0.03 0.1 1 0.2 0.3
D 0.2 0.07 0.2 1 0.1
E 0.42 0.1 0.3 0.1 1
Ana A B C D E
A 1 0.12 0.2 0.39 0.1
B 0.12 1 0.1 0.07 0.1
C ...
D
E
...
我有一個for循環的前面的問題,multiple t-tests,但我努力使它適應這個任務,因爲Wilcox-Test在設計上是如此不同。 下面是for循環我用的t檢驗:
res <- matrix(NA, ncol=5,
dimnames=list(NULL, c("group", "col", "statistic", "estimate", "p.value")))
gr <- levels(cb$group)
for(cl in 2:ncol(cb)){
for(grp in gr){
temp <- cb[cb$group == grp, cl]
res <- rbind(res, c(grp, colnames(cb)[cl],
unlist(t.test(temp, mu = mean(cb[,cl]), alternative="two.sided"))[c(1, 5, 3)]))
}
}
你有一個想法如何改變這種for循環執行威爾科克斯測試?
我剛試過。非常令人印象深刻,非常感謝你! –