Repeated measures ANOVA Matlab (Statistic)

25 views (last 30 days)
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!
Thanks in advance

Accepted Answer

Jeff Miller
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 Comments
Jakob Kruppa
Jakob Kruppa on 14 Jan 2022
Thanks for your quick reply!
But why does only one p-value come out?
Actually, groups A,B,C and D should each be tested with the other for significant change.
So A to B and A to C .... or B to C and so on. So there should be 7 p-values in total.
Also, I am still given a significant p-value<0.05 [pValue=2.5462e-31] if I change vectors A and B like this:
A = [10 10 10 10 10 10 10 10 10 10]';
B = [10 10 10 10 10 10 10 10 10 10]';
And what does the whole thing look like in addition with a post hoc test?
Thanks for the help in advance! :)
Jeff Miller
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).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!