How to run anova after fitlmematrix to obtain the F statistics

2 Ansichten (letzte 30 Tage)
Xiaowei Zhuang
Xiaowei Zhuang am 10 Apr. 2024
Beantwortet: Shivansh am 22 Jun. 2024
I am following the example of fitlmematrix under longitudinal data with a covariate at: https://www.mathworks.com/help/stats/fitlmematrix.html;
Breifly I build design matrix of the fixed and random effect for the model
y ~ Intercept + InitWeight + PrgB + PrgC + PrgD + Week + Week_PrgB + Week_PrgC + Week_PrgD + (Intercept + Week | Subject)
And then run the code:
lme = fitlmematrix(X,y,Z,G,'FixedEffectPredictors',{'Intercept','InitWeight','PrgB','PrgC','PrgD','Week','Week_PrgB','Week_PrgC','Week_PrgD'},'RandomEffectPredictors',{{'Intercept','Week'}},'RandomEffectGroups',{'Subject'})
I obtain the t-stats for each term:
Fixed effects coefficients (95% CIs):
Name Estimate SE tStat DF pValue Lower Upper
{'Intercept' } 0.66105 0.25892 2.5531 111 0.012034 0.14798 1.1741
{'InitWeight'} 0.0031879 0.0013814 2.3078 111 0.022863 0.00045067 0.0059252
{'PrgB' } 0.36079 0.13139 2.746 111 0.0070394 0.10044 0.62113
{'PrgC' } -0.033263 0.13117 -0.25358 111 0.80029 -0.29319 0.22666
{'PrgD' } 0.11317 0.13132 0.86175 111 0.39068 -0.14706 0.3734
{'Week' } 0.1732 0.067454 2.5677 111 0.011567 0.039536 0.30686
{'Week_PrgB' } 0.038771 0.095394 0.40644 111 0.68521 -0.15026 0.2278
{'Week_PrgC' } 0.030543 0.095394 0.32018 111 0.74944 -0.15849 0.21957
{'Week_PrgD' } 0.033114 0.095394 0.34713 111 0.72915 -0.15592 0.22214
I am wondering, if it is possible to obtain a F-stats for all Programs (Prg). Anova(lme) in this case will give F-stats for individual terms instead of grouping them together.
Term FStat DF1 DF2 pValue
{'Intercept' } 6.5184 1 111 0.012034
{'InitWeight'} 5.326 1 111 0.022863
{'PrgB' } 7.5406 1 111 0.0070394
{'PrgC' } 0.064305 1 111 0.80029
{'PrgD' } 0.74261 1 111 0.39068
{'Week' } 6.593 1 111 0.011567
{'Week_PrgB' } 0.16519 1 111 0.68521
{'Week_PrgC' } 0.10251 1 111 0.74944
{'Week_PrgD' } 0.1205 1 111 0.72915

Antworten (1)

Shivansh
Shivansh am 22 Jun. 2024
Hi Xiaowei,
It seems like you want obtain the F-statistics for all the program terms (PrgB, PrgC, and PrgD) together. You can do this by first creating a contrast matrix that represents the hypothesis you want to test (i.e., the combined effect of PrgB, PrgC, and PrgD) and then using the "coeftest" function to test the joint hypothesis.
You can refer to the below sample code for a better idea of the approach:
% Number of fixed effects
numFixedEffects = length(lme.Coefficients.Estimate);
% Contrast matrix to test PrgB, PrgC, and PrgD together
C = zeros(3, numFixedEffects);
% Indices of PrgB, PrgC, and PrgD in the fixed effects
idxPrgB = find(strcmp(lme.Coefficients.Name, 'PrgB'));
idxPrgC = find(strcmp(lme.Coefficients.Name, 'PrgC'));
idxPrgD = find(strcmp(lme.Coefficients.Name, 'PrgD'));
C(1, idxPrgB) = 1;
C(2, idxPrgC) = 1;
C(3, idxPrgD) = 1;
[p,F] = coefTest(lme, C);
You can refer to the following documentation for more information about "coeftest":
I hope it helps!

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by