按因子应用t.test

时间:2019-01-19 04:32:43

标签: r

我有如下数据:

Replicate    Group   Value
1            A       1.0
1            A       1.1
1            A       1.1
1            B       2.0
1            B       2.0
1            B       2.2
2            A       1.1
2            A       1.2
2            A       0.9
2            B       2.2
2            B       2.4

我想使用t.test()来获取每个单独的副本的A和B,p值和95%CI之间的均值差。我如何最轻松地做到这一点?

下面是将上面的玩具示例放入数据框的代码:

df = data.frame("Replicate"=c(1,1,1,1,1,1,2,2,2,2,2), "Group"=c("A","A","A","B","B","B","A","A","A","B","B"), "Value"= c(1.0, 1.1, 1.1, 2.0, 2.0, 2.2, 1.1, 1.2, 0.9, 2.2, 2.4))

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我不确定我是否理解“对于每个单独的副本” 的意思。为了表征不同() -> new LinkedHashMap<>(unsortedMap.size())的{​​{1}}之间的均值差异,我们可以将TreeMap中的Tree指定为

Value

95%CI由...给出

Group

再三考虑一下,如果您真的想对formula 1和2分别进行t检验,我们可以t.test ttest <- t.test(Value ~ Group, data = df) ttest # #Welch Two Sample t-test # #data: Value by Group #t = -12.729, df = 6.4248, p-value = 8.52e-06 #alternative hypothesis: true difference in means is not equal to 0 #95 percent confidence interval: #-1.3001853 -0.8864814 #sample estimates: #mean in group A mean in group B # 1.066667 2.160000 ttest$conf.int #[1] -1.3001853 -0.8864814 #attr(,"conf.level") #[1] 0.95 Replicate,然后group_byReplicate到嵌套数据。然后,我们可以从nest的{​​{1}}中提取相关数量:

Replicate