我的df:
df <- data.frame(
measurement = runif(120, min=1, max=25),
group = rep(c("A","B","C","D"), each=3, times=10)
)
执行t.test并将结果放在新的df
上ttest_results <- data.frame(pairwise.t.test(df$measurement, df$group))
我收到此错误:
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class ""pairwise.htest"" to a data.frame
我发现这个解决方案有效,但老实说我想通过R
解决这个问题write.table(test[["p.value"]], file="output.csv", sep=",")
答案 0 :(得分:0)
根据@ user3710546的评论,以下是如何获得成对比较的 p值输出:
# Create dummy dataframe
df <- data.frame(
measurement = runif(120, min=1, max=25),
group = rep(c("A","B","C","D"), each=3, times=10)
)
# Run your test and save it to its own object
ttest_results <- pairwise.t.test(df$measurement, df$group)
# Get p-values in a dataframe
ttest_results$p.value
在RStudio中添加$符号时,您会注意到p值区域实际存储在表格中。
结果如何:
A B C
B 1 NA NA
C 1 0.3999325 NA
D 1 1.0000000 1
现在,您可以很好地显示您的p值并检查成对比较:
# Convert the data to a table
m<-as.table(p.vals)
# Plot p-values
# ----------------------
library("gplots")
windows(3,3)
balloonplot(t(m),
main ="p.values",
xlab ="",
ylab="",
label = FALSE,
show.margins = FALSE)