Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R T-Test from N/Mean/SD

I know that if I have a set of data, I can run t.test to do a T test. But I only know the count, mean and standard deviation for each set. I'm sure there must be a way to do this in R, but I can't figure it out. Any help?

like image 287
Xodarap Avatar asked Apr 03 '11 01:04

Xodarap


3 Answers

Using the formula for t-tests with unequal variance and unequal sample sizes. Note that this is for an unpaired t-test.

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)
like image 132
Ari B. Friedman Avatar answered Nov 15 '22 09:11

Ari B. Friedman


You can certainly calculate the formula by hand or simulate. But if you want a quick function call, there is ?tsum.test in the BSDA package. For example, this makes the Welch t-test quite easy. Using @AriB.Friedman's numbers:

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
like image 29
gung - Reinstate Monica Avatar answered Nov 15 '22 10:11

gung - Reinstate Monica


If you don't want to recode the formula yourself, you can always simulate data set that has the exact summaries that you have, then analyse the simulated data. The mvrnorm function in the MASS package can be used to generate normal data with a given mean and variance (set the empirical argument to TRUE).

like image 40
Greg Snow Avatar answered Nov 15 '22 10:11

Greg Snow