# How can I calculate a confidence interval for the mean based on non-independent data?

In Chemical industrial, samples are often analyzed multiple times, e.g. 5 samples and each was analyzed 2 times with 10 data points in total. What would be the confidence interval for the mean estimated from these data? The degrees of freedom is somewhere from 4 to 10 depending on the correlation between repeats.

-
The answer will depend on 1) the distribution you expect for the concentration of each sample (if you sample from a slightly heterogeneous solution), and on 2) the distribution of the errors of the analysis method. I assume there are usual hypothesis for this, like for 2) centered gaussian error, are you aware of this? –  Elvis Jan 5 '12 at 20:43
Let's assume 2), i.e. the measurement error follows gaussian distribution. –  Aldous Wong Jan 7 '12 at 10:45

My question (in the comments) was mainly on the variation between samples. Is it normal? It is unclear to me, I suspect that for small concentrations it is not the good model. Anyway, let’s assume it is normal.

Let’s formalize a little bit. If $c$ is the true concentration, the concentration of sample $i$ is $C_i = c + E_i$ where $E_i \sim \mathcal N(0, \sigma_s^2)$ for $i=1,\dots,n$.

Each sample is analyzed $m$ times ($m=2$ in your case), and the measurement error is gaussian: this leads to measures $X_{ij} = c + E_i + F_{ij}$ where $F_{ij} \sim \mathcal N(0, \sigma_m^2)$ for $j=1,\dots,m$. All errors $E_i$ and $F_{ij}$ are independent.

Let’s call $Y_i$ the mean of the $m$ measures of sample $i$: $$Y_i = {1\over m} \sum_{j=1}^m X_{ij}.$$ The distribution of $Y_i$ is $\mathcal N\left(c, \sigma_1^2\right)$ where $\sigma_1^2 = \sigma^2_s + {1\over m} \sigma^2_m$.

Now we are in a perfectly classical situation. All $Y_i$ are independent, with the same normal distribution. The unknown concentration $c$ will be estimated by the sample mean $\hat c = {1\over n} \sum_{i=1}^n Y_i$. The variance $\sigma_1^2$ will be estimated as usual by $s_1^2 = {1\over n-1}\sum_i (Y_i - \hat c)^2$.

A confidence interval of level $1-\alpha$ is given by $$\hat c \pm t^{n-1}_{1-\alpha/2} \sqrt{ {s_1^2 \over n} },$$ where $t^{n-1}_{1-\alpha/2}$ is the $1-\alpha/2$-th quantile of the distribition $t(n-1)$.

The answer to your question is that there are $n-1$ df, but the estimation of variance is not to be done as if all measures were independent. You have to follow this two steps procedure:

1. compute the means of all $m$ measures of each sample;
2. treat them as $n$ independent measures.

If you have two samples, each analysed 5 or more times, leading to average measures of 50 and 60, you can compute a 90% confidence interval with \begin{align*} & \hat c \pm t^{1}_{0.95} \sqrt{ {s_1^2 \over 2} }\\ =& 55 \pm 6.31 \sqrt{ {50\over 2}}\\ =& [23.4 \,;\, 86.6] \end{align*}
Alternatively, if you are only interested in a lower bound of the concentration (which is Hahn question, does the average exceed 40 ?), you can say that $[23.4,+\infty)$ is a 95% one-side confidence interval.