Why is my Mixed ANOVA including the intercept as an interaction term?

7 ビュー (過去 30 日間)
Dan
Dan 2024 年 8 月 30 日
編集済み: Adam Danz 2024 年 9 月 16 日
Hi there,
I have been getting different outputs from Matlab to JASP and SPSS, both of which agree that Matlab is wrong, which I think is due to the intercept being included as an interaction term in the model spec.
I have run a 2b*6w*2w Mixed ANOVA in Matlab. (Between-2=Consciousness, Within-6 = Conguency, Within-2 =Target) However I am getting the intercept as an interaction term in my ranova table:
Matlab Output
The factors Congruency and Target should be reported only as a main effects, not as an interaction with the intercept.
I'm including a JASP output so to compare the difference between the two softwares.
Could you take a look at my code, I think I've done something wrong in the Wilkinson notation of the model specification, and tell me how I stop it using the intercept as an interaction term.
OverallDataTable=readtable('Data.xlsx')
WithinDesign=table(categorical({'Related Hand','Related Foot','Unrelated Hand','Unrelated Foot', ...
'Neutral Hand','Neutral Foot','Related Hand','Related Foot','Unrelated Hand','Unrelated Foot', ...
'Neutral Hand','Neutral Foot'}'),categorical({'BP','BP','BP','BP','BP','BP','O','O','O','O','O','O'}'), ...
'VariableNames',{'Congruency','Target'});
OverallMixedANOVA=fitrm(OverallDataTable,'BP_RH_Con-O_NF_Sub~Consciousness',WithinDesign=WithinDesign);
OverallMixedANOVATable=ranova(OverallMixedANOVA,"WithinModel",'Congruency*Target')
Thanks for any and all advice
Dan

採用された回答

Jeff Miller
Jeff Miller 2024 年 8 月 31 日
I think you need
OverallDataTable.Consciousness = categorical(OverallDataTable.Consciousness);
  2 件のコメント
Dan
Dan 2024 年 8 月 31 日
Thank you so much!
I've been stuck on this for a week! Typically, its one of those simple things that I completely overlooked!
Thanks again!
Adam Danz
Adam Danz 2024 年 9 月 5 日
編集済み: Adam Danz 2024 年 9 月 16 日
Thanks @Jeff Miller. Good find.
The doc page for fitrm states that "fitrm treats the variables used in model terms as categorical if they are categorical (nominal or ordinal), logical, character arrays, string arrays, or cell arrays of character vectors". I am just now realizing that the Consciousness variable is double, not logical.
Another solution would be to set Consciousness to logical.

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

その他の回答 (1 件)

Adam Danz
Adam Danz 2024 年 8 月 30 日
You can remove the interaction term by including "-1" in the model spec (doc). I also included terms for Congruency and Target in the WithinModel so the table rows match the JASP version.
format longg
% No change here
OverallDataTable=readtable('Data.xlsx')
OverallDataTable = 195x14 table
ID BP_RH_Con BP_RF_Con BP_UH_Con BP_UF_Con BP_NH_Con BP_NF_Con O_RH_Sub O_RF_Sub O_UH_Sub O_UF_Sub O_NH_Sub O_NF_Sub Consciousness __ ________________ ________________ ________________ ________________ ________________ ________________ ________________ ________________ ________________ ________________ ________________ ________________ _____________ 1 569.066666666667 654.315789473684 635.026315789474 649.6 626.857142857143 596.380952380952 445.022222222222 505.619047619048 530.883720930233 509.276595744681 568.756097560976 533.609756097561 0 2 516.389130434783 510.76 504.940425531915 511.80652173913 491.534782608696 526.611111111111 468.991489361702 490.810869565217 508.45 505.704347826087 551.667441860465 551.068181818182 0 3 623.022222222222 627.739130434783 607.152173913043 654.431818181818 621.477272727273 638.767441860465 615.217391304348 594.382978723404 599.826086956522 610.702127659574 596.282608695652 622.531914893617 0 4 580.157142857143 558.366666666667 531.086046511628 517.976086956522 544.635555555555 535.739534883721 444.551063829787 473.338095238095 481.334782608696 493.012765957447 531.772093023256 562.148780487805 0 6 583.673913043478 551.702127659574 604.402272727273 558.8625 598.448888888889 583.520454545455 522.332608695652 557.708510638298 561.627272727273 524.172340425532 510.435555555555 517.533333333333 0 7 564.980952352381 561.772727295455 568.049999890476 627.110810659459 529.464285785714 567.121428557143 501.961363586364 701.47142855 595.478378335135 515.5000000625 833.782142807142 720.8093749 0 8 520.95652173913 459.520833333333 494.702127659574 462.063829787234 522.155555555556 483.957446808511 424.666666666667 457.195652173913 461.173913043478 442.595744680851 479.571428571429 476.777777777778 0 9 646.193333328889 679.317777784444 659.010869565217 669.291489378723 694.668888893333 691.336956530435 744.278723404255 665.540425542553 680.986956530435 696.097826073913 686.900000004545 682.380000008889 0 10 584.834210536842 520.789130428261 564.992857147619 506.754347821739 546.765116269767 555.607142840476 465.568085108511 566.152380957143 565.964102582051 489.133333335556 595.126315797368 514.640909088636 0 11 575.91914893617 578.030434782609 574.26170212766 574.474468085106 563.306521739131 552.976595744681 565.846808510638 528.321276595745 510.989130434783 482.934042553191 520.660416666667 505.821739130435 0 12 487.04347826087 464.979166666667 503.104166666667 469.765957446808 515.45652173913 472.708333333333 491.239130434783 503.978260869565 491.739130434783 483.595744680851 479.282608695652 480.510638297872 0 13 516.035555564445 500.477777733333 581.146341426829 469.20217393913 501.686046523256 478.45869563913 503.948837202326 473.359090925 446.402173913043 472.631111135556 474.56444448 495.333333288889 0 14 562.319047607143 559.52619047619 579.676744183721 512.436363643182 580.671739128261 485.810869565217 467.144444431111 479.540909077273 468.99333334 425.502173919565 564.313333324444 536.716279076744 0 15 567.531914893617 571.222727272727 555.810869565217 545.786956521739 586.253191489362 559.79375 498.34 509.959574468085 522.108510638298 489.197826086956 519.334042553192 523.15 0 16 597.374418604651 597.123404255319 618.056521739131 603.01914893617 592.311111111111 619.293617021277 561.226086956522 531.121739130435 534.04 532.04 583.576086956522 593.095744680851 0 17 584.972727272727 635.369230769231 600.997619047619 606.004878048781 571.816279069767 630.952380952381 561.440425531915 491.786956521739 562.3 528.339130434783 548.782222222222 530.697727272727 0
WithinDesign=table(categorical({'Related Hand','Related Foot','Unrelated Hand','Unrelated Foot', ...
'Neutral Hand','Neutral Foot','Related Hand','Related Foot','Unrelated Hand','Unrelated Foot', ...
'Neutral Hand','Neutral Foot'}'),categorical({'BP','BP','BP','BP','BP','BP','O','O','O','O','O','O'}'), ...
'VariableNames',{'Congruency','Target'})
WithinDesign = 12x2 table
Congruency Target ______________ ______ Related Hand BP Related Foot BP Unrelated Hand BP Unrelated Foot BP Neutral Hand BP Neutral Foot BP Related Hand O Related Foot O Unrelated Hand O Unrelated Foot O Neutral Hand O Neutral Foot O
OverallMixedANOVA=fitrm(OverallDataTable,'BP_RH_Con-O_NF_Sub~Consciousness',WithinDesign=WithinDesign);
%% New WithinModel spec
OverallMixedANOVATable=ranova(OverallMixedANOVA,"WithinModel",'Congruency+Target+Congruency*Target-1')
OverallMixedANOVATable = 9x8 table
SumSq DF MeanSq F pValue pValueGG pValueHF pValueLB ________________ ___ ________________ ________________ ____________________ ____________________ ____________________ ____________________ (Intercept):Congruency 107194.152414621 5 21438.8304829243 8.36833441555248 9.28137173697959e-08 2.98529873459618e-06 2.40828537573198e-06 0.00425684527499502 Consciousness:Congruency 31382.590285273 5 6276.5180570546 2.44994716985711 0.0322555870821942 0.0497372650079374 0.04841523524835 0.119166973697714 Error(Congruency) 2472232.87080552 965 2561.89934798499 (Intercept):Target 485005.468185154 1 485005.468185154 32.4508255186805 4.50733949742911e-08 4.50733949742911e-08 4.50733949742911e-08 4.50733949742911e-08 Consciousness:Target 70491.4473790544 1 70491.4473790544 4.71645333817901 0.0310949296797302 0.0310949296797302 0.0310949296797302 0.0310949296797302 Error(Target) 2884550.82000456 193 14945.8591710081 (Intercept):Congruency:Target 101277.946737745 5 20255.589347549 9.2725171215368 1.22962731392545e-08 1.11261351901247e-06 8.90177532870524e-07 0.00265102819545689 Consciousness:Congruency:Target 15566.2107964413 5 3113.24215928826 1.42516669005159 0.212538545990976 0.22908775024349 0.228299426473737 0.234020137725994 Error(Congruency:Target) 2108019.15641491 965 2184.47580975638
Comparing these results with your MATLAB table screen shot does not indicate that removing the main intercept term made a difference for the other terms. I also noticed that data in rows 1, 4, and 7 above do not match the JASP table but the other rows do match. I'm not familiar with JASP but I did see that they may have recently changed thier default ANOVA methods (JASP doc).
Make sure you're using the same alpha value (0.05) in both cases.
Your data does not contain any missing data (NaNs) so that rules out the possibilty that treatment of missing data differs.
I noticed that the JASP table warns against sphericity assumption violations which makes me wonder if any corrections are being applied in JASP (e.g. Greenhouse-Geisser or Huynh-Feldt adjustments).
There's a possibilty that sum of squares is calucated differently but I would expect that to affect all SumSq values, not just select rows.
Lastly, there could be differences in how the overall mixed ANOVA model was specified.
Unfortunately I don't have time to dig further but I would chose one of the rows that have conflicting results and compute the SumSq to make sense of it.
I plotted the data as a sanity check.
M = table2array(OverallDataTable);
boxchart(M(:,2:end-1))
xline(6.5) % separate conscious and subc. groups
  1 件のコメント
Dan
Dan 2024 年 8 月 31 日
Thanks so much for your work on this.
I had been stuck on this for ages. From the above answer it turns out to be something super simple I should've already known!
Nonetheless, I really appreciate your input, it'll help me methodically debug code in future!
Thanks again

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

カテゴリ

Help Center および File ExchangeRepeated Measures and MANOVA についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by