R T-Test from N/Mean/SD

Xodarap picture Xodarap · Apr 3, 2011 · Viewed 18.2k times · Source

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?

Answer

Ari B. Friedman picture Ari B. Friedman · Apr 3, 2011

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)