Reputation: 11849
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?
Upvotes: 7
Views: 26150
Reputation: 11893
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
Upvotes: 11
Reputation: 49640
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).
Upvotes: 6
Reputation: 72731
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)
Upvotes: 15