Discrepancy between anovan and fitlme for interactions
조회 수: 2 (최근 30일)
이전 댓글 표시
I have run into an issue where anonvan and fitlme give different answers but only for models with interactions.
Here is a minimal example:
% some fake data
X = [1 1 1 1 0 0 0 0]'; % label 1
Y = [1 0 1 0 1 0 1 0]'; % label 2
Z = [
-1.1719
1.9764
0.0093
1.1649
0.7713
-0.0083
0.3148
-0.6221]; % data
%% model with interactions - discrepancy
% statistics for main effects are different
% statistics for interaction are identical
[P,T,STATS,TERMS] = anovan(Z, [X Y], 'model', 'interaction', 'varnames', {'X', 'Y'});
tbl = table(Z, X, Y, 'VariableNames',{'Z', 'X', 'Y'} );
mdl = fitlme(tbl,'Z ~ X*Y', 'FitMethod','reml');
anova(mdl,'dfmethod','satterthwaite')
Note how p value and fStat are the same for the interaction term (up to rounding error) but different for the main effects terms.
This difference goes away when I remove the interaction term:
%% model without interactions - no discrepancy
% all statistics identical
[P,T,STATS,TERMS] = anovan(Z, [X Y],'varnames', {'X', 'Y'});
tbl = table(Z, X, Y, 'VariableNames',{'Z', 'X', 'Y'} );
mdl = fitlme(tbl,'Z ~ X + Y', 'FitMethod','reml');
anova(mdl, 'dfmethod','satterthwaite')
Note: I used the Satterthwaite dfmethod and reml FitMethod as described in a previous post on a similar issue (https://www.mathworks.com/matlabcentral/answers/247286-discrepancy-between-anova-and-fitlme).
댓글 수: 0
답변 (1개)
Sanjana
2023년 6월 16일
Hi Robert,
I understand you are facing an issue with “annovan” and “fitlme” functions which result in different answers when used for models with interactions.
One reason for this is that they estimate different types of model parameters. “ANOVAN” treats all factors (both continuous and categorical) as fixed-effects parameters and estimates the marginal means of each factor level. If the model includes interactions, “ANOVAN” will also estimate the marginal means for each combination of factor levels.
On the other hand,” fitlme“ treats categorical factors as fixed-effects parameters and continuous factors as random-effects parameters. If the model includes interactions, “fitlme” will estimate and test the interaction between the fixed and random effects and will estimate the variance of the random effects.
Therefore, the two methods are not measuring the same thing, and it's possible that they will give different results. One way to reconcile the results is to make sure that the model structure and the methods used are identical across “ANOVAN” and “fitlme”.
Please refer to the following links, for further information,
Hope this helps!
댓글 수: 0
참고 항목
카테고리
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!