# hypothesis testing with data that are not equally independent

I think the easiest way to explain my question is with an example scenario:

Let's say we have 10 groups of 5 people and each group is in an identical circular room in which we are allowing them to move around the room at will for 20 minutes. In this scenario, We are interested in how close each person chooses to stand relative to the person closest to them. Specifically, we will measure how close each person is standing to their nearest neighbor at the top of every minute, and then take the median of these values for each individual (so we will end up with 5 data points for each group of people).

Not let's say we also perform this process with a completely different set of people (again we'll say we have 10 groups of 5) and we want to know how the nearest neighbor distances for this set of people differs from the other set of people.

So, we will have 50 measurements for each set of people (1 per person). My question relates to how the dependence/independence of our measurements will affect our hypothesis testing because measurements from people that were in a room together will not be completely independent (the behavior of any person in the group will have an effect on the behavior of others in the group), but measurements from different groups are independent.

Is there a particular statistical approach that deals with this type of issue? Or is the only solution to instead compare groups instead of individuals (median nearest neighbor distance per group instead of median nn distance per individual)?

The idea behind comparing each individual vs every group is that it would allow us to capture individual differences (i.e. we expect some people to stand particularly close and others to stand particularly far, which would not be illustrated in analysis of group medians alone).

I know the example is imperfect so please let me know if there is anything I need to clarify.

• The general solution would be to move away from hypothesis testing into estimation, ie. to develop a model appropriate for the data. In your example, people are clustered into rooms and this can be represented with a multi-level model. Jun 18 at 12:00

I would set this up as a mixed model with group as a random effect to account for the non-independence within groups, and individual as a random effect to account for the non-independence within individuals (i.e. multiple measurements on the same person).

Let's call the set of initial 10 groups 'treatment 1' and the next set of 10 groups 'treatment 2'.

Then, if all individuals are referred to by codes (e.g. 'individual 1' within group 1 within treatment 1), the model would be something like:

lmer(distance ~ treatment + (1|group/individual), data = dat)


or equivalently

lmer(distance ~ treatment + (1|group) + (1|individual:group), data = dat)


This is a nested random effect, which is needed because 'individual 1' can refer to different individuals depending on which group they are in. But if individuals are identified by unique names and there is no ambiguity about which group they belong to, then you do not need nested random effects. Crossed (i.e. non-nested) random effects are sufficient and the model is simpler:

lmer(distance ~ treatment + (1|group) + (1|individual), data = dat)


See this excellent answer to understand the nested/crossed random effect distinction better.

• I have a follow-up questions if that's alright: let's say what we're calling treatment 2 here would actually consist of 'random' control data that is produced by taking data for individuals from treatment 1 and forming fake groups. If i understand correctly, this (same individuals in multiple treatments) would normally be treated as a crossed random effect, however since the intention of this experimental design is to compare our collected data to 'randomness', I believe the we can ignore that individuals are being reused. Does that make sense?
– Alex
Jun 24 at 19:40
• @Alex Hmmm. This sort of randomisation procedure would need some thought. I suggest posting it as a new question with more details about what you're trying to establish/understand with the experiment and model.
– mkt
Jun 24 at 20:00