【问题标题】:how do I calculate t.-statistic value and find two-sided P value using R?如何计算 t.-statistic 值并使用 R 找到两侧 P 值?
【发布时间】:2020-08-27 17:25:45
【问题描述】:

下面是我的数据集

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 列)构建仅 Regular Oil Diet 的 t 统计量,以及如何找到两侧 p 值作为 t 分布中远离 0 的值比使用 R 的值的比例?

【问题讨论】:

  • 请不要发布您的数据图像。我们不能将它们复制并粘贴到 R 中来尝试。图像也无法搜索并且与屏幕阅读器混淆。使用dput(ex0112) 并将其粘贴到您的问题中。
  • 非常感谢@BenNorris 我已经更新了我的问题。我是这个编程世界的新手。我还在学习:)

标签: r statistics


【解决方案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

【讨论】:

    猜你喜欢
    • 2018-02-06
    • 2017-12-20
    • 2014-06-23
    • 2019-09-09
    • 2020-10-15
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多