I have run a three-way repeated measures ANOVA with 1 within-subject factor and 2 between-subject factors using Statistics and Machine Learning Toolbox. I can make the pairwise comparisons for the 2-way interactions, but I can not do the same for 3-way interactions. I looked at a similar question but the answer provided there works for 3 within-subject factors, not for my case:
https://www.mathworks.com/matlabcentral/answers/140799-3-way-repeated-measures-anova-pairwise-comparisons-using-multcompare
Here is my code:
% generate random data for the example
data = randn(168,3); % define a variable that stores the treatment information
Treatment = cell(168, 1); for i=1:25;Treatment{i} = 'control';end; for i=26:52;Treatment{i} = 'treatment';end; for i=53:78;Treatment{i} = 'control';end; for i=79:98;Treatment{i} = 'treatment';end; for i=99:137;Treatment{i} = 'control';end; for i=138:168;Treatment{i} = 'treatment';end; % define a variable that stores the environment type
Etype = cell(168, 1); for i=1:52;Etype{i} = 'A';end; for i=53:98;Etype{i} = 'B';end; for i=99:168;Etype{i} = 'C';end; % Store the data in a proper table format to do repeated measures analysis
all_table = table(Etype, Treatment, data(:, 1), data(:, 2), ... data(:, 3), ... 'VariableNames', {'Etype', 'Treatment', 'pre', 'during', 'post'}); % Define the within subject parameter (pre, during, post)
Time = [0 1 2]; % 0: pre, 1: during, 2: post
% Fit repetitive model to data
rm = fitrm(all_table, 'pre-post ~ Treatment*Etype', ... 'WithinModel', Time, 'WithinModel', 'separatemeans'); % Run repetitive measures ANOVA on model:
ranova(rm) % make pairwise comparisons for the two-way interactions
multcompare(rm, 'Time', 'By', 'Etype') multcompare(rm, 'Time', 'By', 'Treatment') multcompare(rm, 'Treatment', 'By', 'Etype') % but how can I make pairwise comparisons for the 3-way interaction?
% These do not work:
multcompare(rm, 'Time', 'By', 'Treatment', 'Etype') multcompare(rm, 'Time', 'By', {'Treatment', 'Etype'})
Thanks
Best Answer