来自N/Mean/SD的R T检验

Xod*_*rap 5 statistics r hypothesis-test

我知道如果我有一组数据,我可以跑去t.test做T测试.但我只知道每组的计数,平均值和标准偏差.我确信必须有一种方法可以在R中做到这一点,但我无法弄明白.有帮助吗?

Ari*_*man 13

使用不等方差和不等样本大小的t检验公式.请注意,这是针对不成对的t检验.

t.test.fromSummaryStats <- function(mu,n,s) {
   -diff(mu) / sqrt( sum( s^2/n ) )
}

mu <- c(.1,.136)
n <- c(5,7)
s <- c(.01,.02)
t.test.fromSummaryStats(mu,n,s)
Run Code Online (Sandbox Code Playgroud)


gun*_*ica 6

您当然可以手动或模拟计算公式.但是,如果你想快速的函数调用,还有?tsum.test在BSDA包.例如,这使得Welch t检验非常简单.使用@ AriB.Friedman的数字:

library(BSDA)
tsum.test(mean.x=.1,   s.x=.01, n.x=5,
          mean.y=.136, s.y=.02, n.y=7)
# 
#         Welch Modified Two-Sample t-Test
# 
# data:  Summarized x and y
# t = -4.0988, df = 9.238, p-value = 0.002538
# alternative hypothesis: true difference in means is not equal to 0
# 95 percent confidence interval:
#  -0.05579113 -0.01620887
# sample estimates:
# mean of x mean of y 
#     0.100     0.136
Run Code Online (Sandbox Code Playgroud)


Gre*_*now 5

如果您不想自己重新编码公式,则可以始终模拟具有所需摘要的数据集,然后分析模拟数据.MASS包中的mvrnorm函数可用于生成具有给定均值和方差的正常数据(将经验参数设置为TRUE).