(How) can “de-meaning” help me solve this “clustering” issue?

I'm not particularly advanced when it comes to statistics and data analysis and have a problem I can't seem to solve. Basically, suppose you're doing school research and have three groups (to which student participants have been randomly assigned) - a control group, and two experimental groups. Your whole participant pool is say 27 students (tiny I know, but helps with the example)

However, within each group you have clusters of students who belong to the same class. For example, within the control group there are 3 students who all belong to class A, 3 who all belong to Class B, and 3 who all belong to class C. Same situation for the other two groups - within each there are small clusters of students (e.g. 3-5 students) who all belong to the same class.

The situation looks like this:

Now I get that there's a problem here and that the problem is one of "clustered data." One solution that has been suggested to me is "de-meaning" for each class, in other words:

Step 1: Calculate the mean for each class (e.g. Class A) Step 2: Subtract the mean for each class from every observation in that class

Now the means of each class become 0 and there are no longer any "between class" differences. This (apparently) gets rid of the clustering problem. You might end up with a set of data that looks like this:

My first question is: is this a good solution to the problem?

My second question is essentially: what do you do next?

I'm assuming you could now just run a normal one-way ANOVA on the data, just as you would have done with the "raw" data if there hadn't been any clustering.

But I've gathered from posts elsewhere that you have to "correct the degrees of freedom" or something like that, because you've "used up" some of them in estimating the means for each class. Can somebody explain this?

Thanks so much for your help! Really appreciate it as this is doing my head in,

Regards

Luke

• It seems to me that you can do a two-way ANOVA with the original data. – Ertxiem - reinstate Monica Mar 27 '19 at 14:54
• Thank you Ertxiem - that option occurred to me too. Somebody told me that the "de-meaning" approach ends up being equivalent to a two-way ANOVA (with original) data as well. Possibly they are the same thing mathematically? – newbie34 Mar 27 '19 at 16:36