Does fitrm & ranova support within subject models without between subject factors
Mostrar comentarios más antiguos
I am trying to use fitrm and ranova (Matlab2014a) to run a repeated measures anova on a 2x2 within subjects design. I currently have 4 variables representing the responses for all subjects in each cell of the 2x2 design.
I do not wish to include a between subject factor but rmfit seems to require at least one.
The code I am using is as follows.
alpha_power = randn(24,4); % This is my data but lets generate it for now
t = table(alpha_power(:,1),alpha_power(:,2), alpha_power(:,3), alpha_power(:,4),'VariableNames',{'Y1','Y2','Y3','Y4'}); % Create a table storing the respones
within = table({'A';'A';'V';'V'},{'T';'S';'T';'S'},'VariableNames',{'Attention','TMS'}); % Create a table reflecting the within subject factors 'Attention' and 'TMS' and their levels.
rm = fitrm(t,'Y1-Y4','WithinDesign',within); % Here the code breaks.
fitrm seems to require terms in the model specification which reflect the predictor variables (e.g. 'Y1-Y4~Gender'), but these are automatically specified as between subject factors, I do not have between subject factors.
Is it possible to specify terms as within subject factors?
1 comentario
This was very helpful. I was wondering if you have figured out how to do a repeated measures anova on that model. I am having trouble finding examples of how to do: ranovatbl = ranova(rm,'WithinModel',WM) with a 2-way repeated measures that's all within. Thank you!
Respuesta aceptada
Más respuestas (3)
Chaoran Zhang
el 7 de Mayo de 2021
Editada: Chaoran Zhang
el 8 de Mayo de 2021
Let me sum up the critical points for problems like this one. Some of them are mentioned in the above answers.
- If you want to do a two way repeated measures ANOVA, which means purely within-subject, you need a constant term on the RHS. (by Tom Lane)
- It is recommanded to use the data type of categorical to mark your within-subject variables. (by Francis Z. Fan)
- If you don't want you model to contain a constant, add '-1' to your Wilkinson notation, because 'Statistics and Machine Learning Toolbox™ notation always includes a constant term unless you explicitly remove the term using -1'.
If you follow the instructions above, you will get a result exactly the same as SPSS!
Here's my test code:
t = table( ...
[3 6 4 3]', ...
[4 6 4 2]', ...
[5 7 5 2]', ...
[4 5 3 3]', ...
[8 9 8 7]', ...
[12 13 12 11]', ...
'VariableNames',{'a1b1','a1b2','a1b3','a2b1','a2b2','a2b3'});
Meas = table(categorical([1 1 1 2 2 2])',categorical([1 2 3 1 2 3])','VariableNames',{'a','b'});
rm = fitrm(t,'a1b1,a1b2,a1b3,a2b1,a2b2,a2b3~1','WithinDesign',Meas);
ranova(rm,'WithinModel','a*b-1')
Here's the output of MATLAB:
SumSq DF MeanSq F pValue pValueGG pValueHF pValueLB
______ __ _______ ______ __________ __________ __________ _________
(Intercept):a 80.667 1 80.667 72.6 0.0033958 0.0033958 0.0033958 0.0033958
Error(a) 3.3333 3 1.1111 1 0.5 0.5 0.5 0.5
(Intercept):b 81.083 2 40.542 153.63 7.0263e-06 0.00094758 0.00072093 0.0011315
Error(b) 1.5833 6 0.26389 1 0.5 0.5 0.5 0.5
(Intercept):a:b 56.583 2 28.292 119.82 1.4572e-05 0.00082622 0.00026348 0.0016322
Error(a:b) 1.4167 6 0.23611 1 0.5 0.5 0.5 0.5
Here's the output of SPSS:
主体内效应检验
测量: score
源 III 类平方和 自由度 均方 F 显著性
a 假设球形度 80.667 1 80.667 72.600 .003
格林豪斯-盖斯勒 80.667 1.000 80.667 72.600 .003
辛-费德特 80.667 1.000 80.667 72.600 .003
下限 80.667 1.000 80.667 72.600 .003
误差 (a) 假设球形度 3.333 3 1.111
格林豪斯-盖斯勒 3.333 3.000 1.111
辛-费德特 3.333 3.000 1.111
下限 3.333 3.000 1.111
b 假设球形度 81.083 2 40.542 153.632 .000
格林豪斯-盖斯勒 81.083 1.034 78.388 153.632 .001
辛-费德特 81.083 1.087 74.562 153.632 .001
下限 81.083 1.000 81.083 153.632 .001
误差 (b) 假设球形度 1.583 6 .264
格林豪斯-盖斯勒 1.583 3.103 .510
辛-费德特 1.583 3.262 .485
下限 1.583 3.000 .528
a * b 假设球形度 56.583 2 28.292 119.824 .000
格林豪斯-盖斯勒 56.583 1.142 49.535 119.824 .001
辛-费德特 56.583 1.383 40.914 119.824 .000
下限 56.583 1.000 56.583 119.824 .002
误差 (a*b) 假设球形度 1.417 6 .236
格林豪斯-盖斯勒 1.417 3.427 .413
辛-费德特 1.417 4.149 .341
下限 1.417 3.000 .472
Jim
el 7 de Abr. de 2014
0 votos
Francis Z. Fan
el 15 de Feb. de 2017
0 votos
before doing ranova, one should convert factors to categorical, like
https://cn.mathworks.com/matlabcentral/answers/140799-3-way-repeated-measures-anova-pairwise-comparisons-using-multcompare
within2 = within; within2.Attention = categorical(within2.Attention); within2.TestCond = categorical(within2.TestCond); within2.TMS = categorical(within2.TMS);
Categorías
Más información sobre Repeated Measures and MANOVA en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!