Repeated-Measures ANOVA across several conditions rather than timepoints

So I have a table T (attached), which has the SSVEP amplitude in the first column, the subject number in the second, then the contrast condition (3rd), value condition(4th) and left/right(5th).
As there are multiple permutations of contrast/value/LR for each subject, I've been trying to do a repeated-measures ANOVA with fitrm and ranova, but I'm running into issues and I don't really understand. Even for the most basic model type I can think of:
rm = fitrm(T,'SSVEP ~ Contrast+Value+LR+Contrast*Value');
ranovatbl = ranova(rm)
I get the following output:
which is clearly incorrect!
From the few examples I have seen online (https://uk.mathworks.com/help/stats/fitrm.html#bt9ol4i-4), there always seems to be multiple measurements at different time points - but as in this repeated measures design, I have multiple conditions rather than multiple timepoints, I'm really pulling up blanks! I am also aware that I should probably be using ranovatbl = ranova(rm,'WithinModel',WM), but I have had absolutely zero success specifying this WM component!
Any help would be amazing!

 Akzeptierte Antwort

fitrm wants all the data for a single subject to be on a single row of the data table. In your case, that would mean a table newT with 5 rows for the 5 Ss and 12 columns for the 12 measurements. Assuming you arrange those 12 columns in the same order as you have your 12 rows for a single subject, you will then need something like this (unchecked):
WithinStructure = table([1 1 2 2 3 3 1 1 2 2 3 3]',[1 2 1 2 1 2 1 2 1 2 1 2]',[1 1 1 1 1 1 2 2 2 2 2 2]',...
'VariableNames',{'Contrast','Value','LR'});
% In the next line, '~1' indicates that there are no between-Ss factors.
rm = fitrm(newT,'col1-col12~1','WithinDesign',WithinStructure,'WithinModel','Contrast*Value*LR');
% You need to specify the repeated-measures factors again when you call ranova, like this:
ranovatable = ranova(rm,'WithinModel','1+Contrast*Value*LR');
In the end, you should get this ANOVA table:
% ANOVA For SSVEP
% Source df MS dfe MSe F pEta^2 P G-G P
% Mean 1 149753159.5 4 12048871.8 12.429 0.757 0.024 **
% LR 1 4966893.5 4 1497203.7 3.3174 0.453 0.143
% Value 1 207.69 4 148015.6 0.00140 0.000 0.972 ??
% LV 1 887505.6 4 150990.3 5.8779 0.595 0.072 *
% Contrast 2 32735265.9 8 3094230.4 10.579 0.726 0.006 0.031 ***
% LC 2 101685.4 8 73574.7 1.3821 0.257 0.305 0.307
% VC 2 58550.9 8 162855.5 0.35953 0.082 0.709 0.621
% LVC 2 59769.2 8 104015.9 0.57462 0.126 0.585 0.582
By the way, that anova table was computed from your original table format (which I prefer) with the command
CallMrf(T,'SSVEP',{},{'Contrast','Value','LR'},'Subject','outFileName')
from RawRT
I hope that helps you.

3 Kommentare

Thank you so much it helped immensely! I am getting different answers to the CallMrf function though. When I specify the model as Contrast+Value+LR+Contrast*Value (my interest), I get the following:
And assuming the differences in p-values are due to the differing model specifications, I changed the definition to what you had suggested in your answer (Contrast*Value*LR), and I get the following:
My concern is that the f-statistics and p-values still differ from that table you supplied and I'm not quite sure why. My code is currently:
WithinStructure = table([1 1 2 2 3 3 1 1 2 2 3 3]',[1 2 1 2 1 2 1 2 1 2 1 2]',[1 1 1 1 1 1 2 2 2 2 2 2]',...
'VariableNames',{'Contrast','Value','LR'});
% Extract the SSVEP vals from the table - 1 row per subject, 12 SSVEP
% values in each column then (3*2*2 conditions)
SSVEP_vals = [];
for s=1:length(allsubj)
SSVEP_vals = cat(2, SSVEP_vals,tab{1+12*(s-1):12*s, 1});
end
SSVEP_vals = SSVEP_vals';
data_tab = array2table(SSVEP_vals, 'VariableNames',{'c1','c2','c3','c4','c5','c6','c7','c8','c9','c10','c11','c12'});
rm = fitrm(data_tab,'c1-c12~1','WithinDesign',WithinStructure,'WithinModel','LR*Value*Contrast');
ranovatable = ranova(rm,'WithinModel','LR*Value*Contrast');
where tab is the original table I attached to the question - so I define the within structure as you suggested, extract the variables from the original table to create the new data_tab table, and then I set up the model and run it through.
Is there something obvious I'm doing wrong? If not, could it be something to do with how the respective functions perform the multiple corrections, I'm not sure if you might have some experience with the comparison between the models output from each respective function - I had a look in the source file (https://github.com/milleratotago/RawRT/blob/master/CallMrf.m) and didn't see anything on corrections for multiple comparisons, and didn't see it on the page for ranova (https://uk.mathworks.com/help/stats/repeatedmeasuresmodel.ranova.html) either!
Thanks again though this was extremely helpful!
Oh, sorry, I always forget that by default fitrm interprets numbers as numerical covariates rather than discrete group indicators. I think you need to use the 'categorical' command like this:
WithinStructure = table([1 1 2 2 3 3 1 1 2 2 3 3]',[1 2 1 2 1 2 1 2 1 2 1 2]',[1 1 1 1 1 1 2 2 2 2 2 2]',...
'VariableNames',{'Contrast','Value','LR'});
WithinStructure.Contrast = categorical(WithinStructure.Contrast);
% and the same for .Value and .LR
% and then fitrm, etc
I think this will give you the correct df for Contrast and its interactions (2) and for the error terms involving contrast (8), and hopefully then also match the CallMrf output.
You can't see anything in the CallMrf source--it just calls the exe file for an old Pascal ANOVA program that does all the actual computations.
That worked perfectly I get the exact same as your table now - thank you so much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by