下面是我的数据集
dput(ex0112)
数据集:
structure(list(BP = c(8L, 12L, 10L, 14L, 2L, 0L, 0L, -6L, 0L,
1L, 2L, -3L, -4L, 2L), Diet = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("FishOil", "RegularOil"
), class = "factor")), class = "data.frame", row.names = c(NA,
-14L))
要找到整个(列BP)的t统计量,我已使用下面的R代码实现了这一点。
library(Sleuth3)
t.test(BP~Diet, data=ex0112)
但是我该如何计算mu为零的假设并仅针对常规油饮食构造(列BP)的t统计量,以及如何找到双向p值t分布中距离值远大于0的值所占的比例,使用R?
答案 0 :(得分:1)
我建议采用下一种方法。您可以在t.test()
中使用一个变量,该变量具有mu
参数的选项以及所需的two-sided
替代选项。这里的代码将您的dput()
数据用作df
:
#Test
test <- t.test(df$BP[df$Diet=='RegularOil'], mu = 0, alternative = "two.sided")
test
#Extract p-value
test$p.value
输出:
One Sample t-test
data: df$BP[df$Diet == "RegularOil"]
t = -0.94943, df = 6, p-value = 0.3791
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-4.088292 1.802578
sample estimates:
mean of x
-1.142857
和p-val:
[1] 0.3790617