MATLAB: Are the values I get for the mean using “anovan” and “multcompare” not accurate

anovanfullmeanmodelmultcompareStatistics and Machine Learning Toolbox

I am using "anovan" and "multcompare" to view the averages of my data, which is broken up into many different groups. However, the mean for some groups is higher than any individual value in that group, so the average seems to be wrong.
Why am I observing this behavior?

Best Answer

The mean is not the value you expect because the default model is a two-way interactions model, meaning that it is not simply using the data points from that group, but fitting a model that involves all points and using it to predict into that group (so, the mean is a 'predicted' mean based on more data than just those 3 points). A 'full' model (what you get if you add the name-value pair 'Model', 'full' to your "anovan" command) is a three-way interactions model, so you can expect it to reproduce the data if there are exactly three grouping variables.
For example, add the name-value pair to your "anovan" command by changing
>> [p,tbl,stats,terms]=anovan(data, groups);
to
>> [p,tbl,stats,terms]=anovan(data, groups, 'Model', 'full');
You can read more about the 'Model' name-value pair on the following documentation page: