# Variance components

I have a set of $N$ bodies, which is a random sample from a population whose mean and variance I want to estimate. A property of each body is being measured $m_i$ times ($m_i>1$) and different for each body index $i$ identifies which body it is; the property is expected to be distributed around zero). I would like to describe the resulting measurement. Particularly I'm interested in average property value and in the variance.

The average value is simple. First calculate the mean values for each body and then calculate the mean of means.

The variance is more tricky. There are two variances: the variance of measurement and the variance of property values. In order to have an idea on the confidence we have in any single measurement, we need to account for both the sources. Unfortunately, I can't think of a good method. It is obvious that putting all the numbers in a single pool and calculating the stdev of this pool isn't a good idea.

Any suggestion?

EDIT Colin Gillespie suggests applying Random Effects Model. This model seems to be the right solution for my case, except for the fact that it is described (in Wikipedia) for the cases where each group (body in my case) is sampled equally ($m_i$ is constant for all the bodies), which is not correct in my case

• The m_i's do not have to be equal Wikipedia has a simplified description of the model. – csgillespie Jul 20 '10 at 14:17

I think if I understand your description correctly, you need to use a linear mixed model. However, this maybe overkill, since these models are used to find differences between groups. For example, if you have two types of bodies and you wish to determine if they are different.

Basically, you have between subject variation and within subject variation.

To fit these models in R, you can use the lmer function from the lme4 library. So if I understand you correctly, your function will look something like this:

#Load the R library
library(lme4)

#data is a R data frame that contains your data
#measurement and Subject are variables
fm1 = lmer(measurement ~ (1|Subject), data)


If you are looking for differences between bodies, then it will look something like:

fm2 = lmer(measurement ~ body + (body|Subject), data)


The command summary(fm1) should give the values you are after.