Matlab repeated measures anova - different result than in other packages

13 ビュー (過去 30 日間)
RP
RP 2019 年 6 月 20 日
コメント済み: Jingwei Sun 2019 年 7 月 7 日
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!

回答 (1 件)

Jeff Miller
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');
  1 件のコメント
Jingwei Sun
Jingwei Sun 2019 年 7 月 7 日
Thanks very much! You saved my day (actually days)!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnalysis of Variance and Covariance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by