Does fitrm & ranova support within subject models without between subject factors
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
Theresa
2014-6-16
编辑:Theresa
2014-6-16
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!
采纳的回答
Tom Lane
2014-4-4
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 个评论
PIT
2014-10-9
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?
Logan
2015-1-30
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???
更多回答(3 个)
Chaoran Zhang
2021-5-7
编辑:Chaoran Zhang
2021-5-8
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
0 个评论
Francis Z. Fan
2017-2-15
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Repeated Measures and MANOVA 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!