# $n$ in standard error for repeated measures

This should be a trivial question but somehow I cannot find a clear cut answer.

I am calculating in r the Standard Error (SE) for the mean of the whole group in a repeated measure experiment, what N should I use?

For example in the first group I have 4 subjects measured twice.

subject<-rep(c("red","green", "blue", "yellow"),2)
condition<-c(rep("before",4), rep("after",4))
measure<-c(10,5,7,8,4,3,6,5)
dat<-data.frame(subject,measure, condition)


I calculate the mean of the 8 measurements mean(dat$measure)(mean=6) but when I calculate the SE shall I divide the Standard Deviation sd(dat$measure)(sd=2.267787) by the square root of 4 or 8?

And in case I have the second measure only for 3 subjects out of 4 shall I divide the overall standard deviation by the square root of 3, 4 or 7?

Let's revisit how do we obtain the expression of the mean.

If all the measurements are independent and IID, then

$$\operatorname{Var}\left( \frac{\sum_{i=1}^n X_i}{n} \right)= \frac{1}{n^2} \operatorname{Var}\left(\sum_{i=1}^nX_i\right)=\frac{ns^2}{n^2}=\frac{s^2}{n}$$

However, in this case, the assumption of independence breaks down as the repeated experiment on the same subject would be highly correlated.

In particular $X_{i1}$ is correlated with $X_{i2}$ where $i \in \{ 1,2,3,4\}$. Suppose $\operatorname{Cov}(X_{i1}, X_{i2}) = c_i$.

$$\operatorname{Var}\left( \frac{\sum_{i=1}^4 \sum_{j=1}^2 X_{ij}}{8} \right)= \frac{8s^2+\sum_{i=1}^4c_i}{8^2} =\frac{s^2}{8}+\frac{\sum_{i=1}^4c_i}{8^2}.$$

Similar result can be obtained if only a few subjects have repeated measurement.

Edit:

$s \approx 2.267787$ If we approximate $c_i = s^2$, then the quantity of interest is approximately

$$\sqrt{\frac{s^2}{8}+\frac{4s^2}{8^2}}=s\sqrt{\frac18+\frac4{8^2}}=\frac{\sqrt{3}}{4}s$$

If you did not repeat the experiment, the quantity of interest would be $\frac{s}{\sqrt{4}}=\frac{s}{2}$ which is bigger than the quantity when you repeat the experiment.

• Thanks, but it is still unclear to me. So also the overall mean should be calculated differently? And how do I calculate the sum of ci and what is s? – have fun Sep 7 '17 at 9:51
• The estimator is fine. In fact it reduces the variance compared to when repeated measurement is not taken. I am just showing the impact of the variance of the estimator of the mean. $s = \operatorname{Var} (X_i)$ and $c_i= \operatorname{Cov}(X_{i1}, X_{i2})=\rho_i \sqrt{\operatorname{Var}(X_{i1})\operatorname{Var}(X_{i1})}$ should be approximately $s^2$. $\rho_i$ is the correlation when the measurement is being repeated. – Siong Thye Goh Sep 7 '17 at 10:02
• I added an example, can you solve it empirically so I can understand it more clearly? – have fun Sep 7 '17 at 10:05
• In my case I did not simply repeat the experiment, the second time the subjects were on a different condition. Does the same formula applies? – have fun Sep 7 '17 at 11:08
• In that case the estimation of $c_i \approx s^2$ is not valid. hmm... do you think it is a valid assumption that all readings do not influence each other in your setting? that is covariance of each reading is independent? if so just divide by $\sqrt{8}$. – Siong Thye Goh Sep 7 '17 at 11:15