Does fitrm & ranova support within subject models without between subject factors

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

Theresa
Theresa el 16 de Jun. de 2014
Editada: Theresa el 16 de Jun. de 2014
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!

Iniciar sesión para comentar.

 Respuesta aceptada

Instead of
'Y1-Y4'
try
'Y1-Y4~1'
You do have to specify a complete formula, but you can include just the constant term on the RHS.

4 comentarios

Let's assume Attention and TMS each have four levels rather than two as above. When I build a model using 'Y1-Y4~1' and run ranova as ranova(rm,'WithinModel','Attention*TMS'), the output is rather confusing to me. As an example, it might look like this...
SumSq DF MeanSq F pValue pValueGG pValueHF pValueLB
__________ __ __________ ______ __________ __________ __________ __________
(Intercept) 4.0584e+05 1 4.0584e+05 422.66 7.1196e-09 7.1196e-09 7.1196e-09 7.1196e-09
Error 8641.8 9 960.2
(Intercept):Attention 3.3996e+05 1 3.3996e+05 390.3 1.0117e-08 1.0117e-08 1.0117e-08 1.0117e-08
Error(Attention) 7839.1 9 871.01
(Intercept):TMS 2.0646e+05 1 2.0646e+05 234.74 9.3829e-08 9.3829e-08 9.3829e-08 9.3829e-08
Error(TMS) 7915.5 9 879.5
(Intercept):Attention:TMS 1.6844e+05 1 1.6844e+05 215.35 1.3643e-07 1.3643e-07 1.3643e-07 1.3643e-07
Error(Attention:TMS) 7039.5 9 782.17
To start, why are the degrees of freedom only one? Since there are four levels of Attention and four levels of TMS, I expect the degrees of freedom for each of these to be 3. Can anyone provide any insight?
Thanks in advance for the help!
I am having similar problems as Abbie.
I tried to do a two way repeated measures Anova with the factors Condition and Trial, with 2 and 30 levels, respectively. I created a data table Y in the wide format with one row for each subject (17 rows) and one column for each level (60 columns). Additionally, I created a table to identify the factor levels for each datapoint:
w1 = cat(1,repmat({'Ground'},30,1), repmat({'Height'},30,1));
w2 = [[1:30]';[1:30]'];
Within = table(w1,w2,'VariableNames',{'Condition','Trial'});
When I test the following model:
rm = fitrm(Y,'Y1-Y60 ~ 1','WithinDesign',Within);
using: ranovatbl = ranova(rm,'WithinModel','Condition+Trial') I got:
ranovatbl =
SumSq DF MeanSq F pValue pValueGG pValueHF
______ __ ______ ________ _______ ________ ________
(Intercept) 1720 1 1720 1.6448 0.32823 0.32823 0.32823
Error 2091.4 2 1045.7
(Intercept):Condition 60.488 1 60.488 0.082038 0.8015 0.8015 0.8015
Error(Condition) 1474.6 2 737.32
(Intercept):Trial 2693.1 1 2693.1 6.0929 0.13232 0.13232 0.13232
Error(Trial) 884.03 2 442.01
pValueLB
________
(Intercept) 0.32823
Error
(Intercept):Condition 0.8015
Error(Condition)
(Intercept):Trial 0.13232
Error(Trial)
In this table you can see that the number of degrees of freedom is 1 for all tested terms, while there are 30 levels for the "Trial" factor. Additionally the factor names Trial and Condition are preceded by "(Intercept):".
Therefore I wonder: Is it possible to do a simple 2 factor within subjects repeated measures Anova using the 2014 statistics toolbox without between subject factors?
Kind regards,
Jonathan
I have the exact same question: I would also like to remove the Intercept from the WithinSubjects terms and to adjust the DFs. Is that possible?
I have the same problem as well and I've seen a similar question posted. Has anyone managed to figure out why the DFs are so low?
Also I've noticed that, like Jonathan and Abbie above, all my pValueGG and HF values are the same as the LB (lower bound). I'm not that familiar with RM ANOVAs but doesn't that mean that the data is completely non-spherical, i.e. as far from a value of 1 as possible???

Iniciar sesión para comentar.

Más respuestas (3)

Chaoran Zhang
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.
  1. 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)
  2. It is recommanded to use the data type of categorical to mark your within-subject variables. (by Francis Z. Fan)
  3. 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
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

Preguntada:

Jim
el 3 de Abr. de 2014

Editada:

el 8 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by