Hi Ehsan,
I recently came across a really similar problem with my research. I suggest a solution could be found by adapting the answer of Matt Mollison in:
In the mentioned case they wanted to test all the possible combinations of levels of the within subject factors, while in this case we both have between-subject factors (Etype and Treatment) and within-subject factors (Time).
I would suggest working around your problem with the following code.
% 1. Convert the between-subject factors to categorical.
etype_cat=categorical(Etype);
treatment_cat=categorical(Treatment);
% 2. Create an interaction factor capturing each combination of levels % of Etype and Treatment (you can check with the function "catogories()")
interaction_cat=etype_cat.*treatment_cat;
% 3. Call fitrm with the modified between design.
t2 = table(interaction_cat, data(:, 1), data(:, 2), data(:, 3), ...
'VariableNames', {'interaction_etype_treat', 'pre', 'during', 'post'});
rm2 = fitrm(t2, 'pre-post ~ interaction_etype_treat', ...
'WithinModel', Time, 'WithinModel', 'separatemeans');
% 4. Use interaction factor interaction_cat as the first variable in % multcompare, 'By' Time
tbl2=multcompare(rm2,'interaction_etype_treat','By','Time');
Best Answer