# Repeated-measures ANOVA with no between-factor

27 views (last 30 days)
Hi all!
I am trying to perform a two-way repeated measures ANOVA by using the function fitrm and ranova. I have two within-factors (e.g. Condition & Side) and no between-subject factors. I tried the code below, based on the different topics on the mathworks help page. Cause I have no between-subjects factor I thought i should use ~1 as constant. However, I keep getting the following error:
Error using RepeatedMeasuresModel.fit (line 1347)
The between-subjects design must have full column rank.
Error in fitrm (line 77)
s = RepeatedMeasuresModel.fit(ds,model,varargin{:});
Error in Statistics_JvdH_versie5 (line 7778)
rm_APMoS_MSZP = fitrm(t_APMoS_MSZP,'CWSaff-CWS2laff~1','WithinDesign',Condition)
Does anyone know how to solve this problem? Or know another way to perform this analysis in matlab.
See code below:
t_APMoS_MSZP = table(MoS_AP_side1_CWS_MSZP,MoS_AP_side2_CWS_MSZP,MoS_AP_side1_FWS_MSZP,...
MoS_AP_side2_FWS_MSZP,MoS_AP_side1_CWS2_MSZP,MoS_AP_side2_CWS2_MSZP...
,'VariableNames',{'CWSside1','CWSside2','FWSside1','FWSside2','CWS2side1','CWS2side2'});
Condition = table([1 1 2 2 3 3]',[1 2 1 2 1 2]','VariableNames',{'Condition' 'Side'});
rm_APMoS_MSZP = fitrm(t_APMoS_MSZP,'CWSside1-CWS2side2~1','WithinDesign',Condition)
[b1_APMoS,A_APMoS,C_APMoS,D_APMoS] = ranova(rm_APMoS_MSZP,'WithinModel','Condition*Side');

Scott MacKenzie on 2 Aug 2021
Edited: Scott MacKenzie on 2 Aug 2021
You don't need a between-subjects factor to use ranova. Your design has two within-subjects factors, and that's just fine.
I see two minor issues in your code. First, you've used "Condition" both as the name of the within-subjects design and as the name of one of the variables in the design. Probably not a good idea. Below, I changed the name of the design to withinDesign. Second, you need to define the Condition and Side variables as categorical. I added two lines to do this, and got a clean run of your code with some random test data. See below.
% test data
MoS_AP_side1_CWS_MSZP = rand(20,1);
MoS_AP_side2_CWS_MSZP = rand(20,1);
MoS_AP_side1_FWS_MSZP = rand(20,1);
MoS_AP_side2_FWS_MSZP = rand(20,1);
MoS_AP_side1_CWS2_MSZP = rand(20,1);
MoS_AP_side2_CWS2_MSZP = rand(20,1);
t_APMoS_MSZP = table(MoS_AP_side1_CWS_MSZP,MoS_AP_side2_CWS_MSZP,MoS_AP_side1_FWS_MSZP,...
MoS_AP_side2_FWS_MSZP,MoS_AP_side1_CWS2_MSZP,MoS_AP_side2_CWS2_MSZP...
,'VariableNames',{'CWSside1','CWSside2','FWSside1','FWSside2','CWS2side1','CWS2side2'});
withinDesign = table([1 1 2 2 3 3]',[1 2 1 2 1 2]','VariableNames',{'Condition' 'Side'});
withinDesign.Condition = categorical(withinDesign.Condition);
withinDesign.Side = categorical(withinDesign.Side);
rm_APMoS_MSZP = fitrm(t_APMoS_MSZP,'CWSside1-CWS2side2 ~ 1','WithinDesign',withinDesign);
[b1_APMoS,A_APMoS,C_APMoS,D_APMoS] = ranova(rm_APMoS_MSZP,'WithinModel','Condition*Side');
Jaimy van den Hout on 2 Aug 2021
Thanks for your answer. I changed my script according to your suggestions. It did not work at first, but I found out that my data in t_APMoS_MSZP was in the wrong format (due to changes I made earlier ....).
Thanks for the help, it works fine now!

R2020b

### Community Treasure Hunt

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

Start Hunting!