Matlab repeated measures anova - different result than in other packages
8 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I have a problem with repeated measures anovas. Is it possible that Matlab uses a different model unlike other packages and programs? I got a very unlikely result in the anova and then ran it again with SPSS and R which both yielded the same result (and not the same as Matlab). I don't see any mistake in my Matlab code and get no error message, just this really unlikely and apparently wrong result. Has anyone else come across this problem or is there a mistake in my code after all which I just did not spot? Thanks in advance!
0 个评论
回答(1 个)
Jeff Miller
2019-6-21
Hi again Rose,
After playing around with this some more, I think the secret is to tell MATLAB that any numerically-coded categories, like this:
% How to reproduce an SPSS mixed ANOVA in MATLAB.
% Here is a toy data set with 6 groups defined by 2 Gender (m/f) x 3 Age (2 people per group).
% Each person is measured 6 times defined by 3 Seasons x 2 Time points.
data = readtable('Sample2x3x3x2.txt'); % File attached
Season = [1,1,2,2,3,3]';
Time = [1,2,1,2,1,2]';
WithinFactors = table(Season,Time);
% CRITICAL: You must indicate that Age, Season, and Time are to be treated
% as categorical indicators rather than as numerical (i.e., regression-type) predictors.
% MATLAB assumes the latter by default.
data.Age = categorical(data.Age);
WithinFactors.Season = categorical(WithinFactors.Season);
WithinFactors.Time = categorical(WithinFactors.Time);
% Run the ANOVA
rm = fitrm(data, 'Seas1Time1-Seas3Time2~Gender*Age','WithinDesign',WithinFactors,'WithinModel','Season*Time');
ranovatable = ranova(rm,'WithinModel','Season*Time');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Analysis of Variance and Covariance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!