# Simulating Hierarchical Data

I want to simulate a dataset that has a "grand mean", and then group means (with some deviation from the grand mean). Nevertheless, I have a bit of a problem conceptualising the problem: if I want (e.g.) the "grand mean" to be $$\mu$$ = 2, and then $$\mu_{group1}$$ = 1.5, and $$\mu_{group2}$$ = 2.5. Is it possible to somehow impose the constraint that $$\mu$$ still equals 2? What if the groups have unequal sizes?

Or am I thinking about it in a completely wrong way?

The problem here is, I think, the use of terminology and notation. Notation is defined within the framework of a model. You can have a model $$Y_{ij}=\mu+\delta_j+\epsilon_{ij},\ \sum_{j=1}^J\delta_j=0,$$ where $$\mu=2$$ is what you call "grand mean", $$J=2$$ is the number of groups, $$\delta_j$$ the group effect for group $$j$$, these adding up to zero, i.e., -0.5 and 0.5 in your example, $$\epsilon_{ij}$$ the i.i.d. random error of observation $$i=1,\ldots,N_j$$ in group $$j$$ with $$N_j$$ observations.

There's nothing wrong with simulating from this model if the $$N_j$$ are not all equal, and the value $$\mu$$ is what it's defined to be ($$\mu=2$$ here) in any case.

However you are right observing that the expected value of the mean of the data sampled from such a model will not be $$\mu$$ unless $$N_1=N_2$$. So $$\mu$$ may not deserve to be called "grand mean" then (a terminology which I believe comes from designs where the group sizes are all the same). It's still $$\mu$$ though.

Ultimately you have to decide what you want: Data with $$\mu=2$$ in the model above, or data for which the expected value of the sample mean is 2, which requires different parameter choices in case the group sizes are not equal.

• Thanks! This clears things up. Looking at the model definitely makes the conceptualisation easier. I should've done in in the first place :)
– Zlo
Dec 2 '21 at 16:41