# Calculating the Standard Error of the Mean (SEM) of a sample from the SEMs of two subsets of that sample

Can you calculate the Standard Error of the Mean (SEM) for a set of data given the SEM from two subsets of the data? How would you do this?

(The two subsets are mutually exclusive and exhaustive.)

Let's say I have the mean and SEM for both men and women on some test, but I do not have access to the original data. I know there are n1 men and n2 women, and each person took the test m times.

It is trivial to calculate the mean of all test takers, but can I calculate the SEM of the entire sample the same way?

Wikipedia tells me that "If the standard error of several individual quantities is known then the standard error of some function of the quantities can be easily calculated in many cases" but does not say anything about which quantities or functions.

• The SEM can have several possible meanings here, js. Does it estimate variation in (a) the mean of all test scores in a group, (b) the mean of the average scores (each average is over $m$ attempts by an individual), or perhaps even (c) some combination of those two sources of variation? The question can be answered in the sense (a), but unfortunately that sense is probably not meaningful (because it confounds two kinds of variation: variation between subjects and variation among subjects). – whuber Nov 29 '11 at 19:34

One simple way to do these types of calculations (simple in the terms of the math you need to think of, more complicated in the actual number of calculations, but we will make the computer do those and save ourselves the thinking) is:

Generate 2 datasets that have the same mean and sem as reported (many statistical packages have functions for generating random values from normal or other distributions, you can then add/subtract and multiply/divide to make the statistics match), then just combine the 2 datasets and calculate the statistics of interest.

Here is a simple example using R:

full.data.stats <- with(ToothGrowth, c(mean=mean(len),
sem=sd(len)/sqrt(length(len))))

m1 <- mean(ToothGrowth$len[ToothGrowth$supp=='OJ'])
s1 <- sd(ToothGrowth$len[ToothGrowth$supp=='OJ'])/sqrt(30)

m2 <- mean(ToothGrowth$len[ToothGrowth$supp=='VC'])
s2 <- sd(ToothGrowth$len[ToothGrowth$supp=='VC'])/sqrt(30)

tmp1 <- scale(rnorm(30))[,1]
tmp2 <- scale(rnorm(30))[,1]

tmp1 <- tmp1*s1*sqrt(30) + m1
tmp2 <- tmp2*s2*sqrt(30) + m2

sim.data.stats <- c( mean=mean( c(tmp1,tmp2) ),
sem = sd( c(tmp1,tmp2) )/sqrt( length( c(tmp1,tmp2))))

all.equal(full.data.stats, sim.data.stats)