# Repeated measures ANOVA Matlab (Statistic)

9 views (last 30 days)
Jakob Kruppa on 13 Jan 2022
Commented: Jeff Miller on 15 Jan 2022
Hi guys,
I need urgent help from you guys for my Thesis!
following situation:
I have to program an anova with measurement repetitions for statistics.
In total, 10 subjects have tested 4 conditions (A, B, C and D), so this results in 10 measurements per condition. All results are pure numerical values, in my case acceleration values.
The whole Data thing looks quite simple in Matlab, e.g. as an array:
A = [10 11 13 16 15 18 17 16 11 12]
B = [20 22 21 25 24 23 22 20 28 26]
C = [49 48 45 46 47 49 40 48 47 45]
D = [70 60 65 66 69 64 62 63 69 67]
My supervisor has now told me that I should evaluate the whole thing with anova with measurement repetitions to test the individual groups among themselves for significance.
Of course, I tried to read up on it and came across the ranova function. However, I don't understand all the, in my opinion, much more complex examples....
Can anyone help me out? This would save my week!

Jeff Miller on 14 Jan 2022
% Note the transpose operator: single-column vectors are more convenient.
A = [10 11 13 16 15 18 17 16 11 12]';
B = [20 22 21 25 24 23 22 20 28 26]';
C = [49 48 45 46 47 49 40 48 47 45]';
D = [70 60 65 66 69 64 62 63 69 67]';
% Load the data into a single array...
data = [A, B, C, D];
%...and convert it to a table which is slightly easier to work with (imo).
tbl = array2table(data,'VariableNames',{'A','B','C','D'});
% Fit the linear model
rm = fitrm(tbl,'A-D~1');
% print the ANOVA table
ranova(rm)
The conditions A-D are significantly different as one can see looking at the numbers, in this case with p value 3.9581e-25
##### 2 CommentsShowHide 1 older comment
Jeff Miller on 15 Jan 2022
Only one p value comes out because the null hypothesis under test says "the true means are identical in all four conditions". That's also why you still get a very small p with your revised A and B: there are still clear differences among ABCD even with those A & B values.
Use the 'multcompare' function if you want the pairwise comparisons A vs B, A vs C, etc. These are the post hoc tests it sounds like you might want. The command for that is
s = multcompare(rm,'Time')
(Time is the default name for your conditions factor comparing ABCD).