Manova method for repeated measures model
5 ビュー (過去 30 日間)
古いコメントを表示
Hi there!
I have a question that I couldn't figure out myself. I have several columns of data and I wish to test if this coulmns have the same mean. I realise I could use repeated measure ANOVA, but the problem is that anova_rm works only for samples (columns) with the same size. I know that it will still work if the missing values are labeled NaN, but in this way we loose data, because here (https://www.mathworks.com/help/stats/anova1.html) it says: "If group contains empty or NaN valued cells or character vectors, anova1 disregards the corresponding observations in y."
I found this solutions to the problem that someone suggested: 1) using anovan function: https://www.reddit.com/r/matlab/comments/2d9dgl/anovas_with_unequal_sample_sizes/
2) using manova function: https://www.mathworks.com/matlabcentral/answers/45926-repeated-measures-anova-in-built-in-function (In my case there are not matrices of different size but only vectors)
I tried both solutions:
a = rand(300,1); b = rand(700,1); c = rand(500,1); X = [a;b;c]; g = [ones(size(a,1),1); 2*ones(size(b,1),1); 3*ones(size(c1,1),1)];
Both functions anovan(X,g) and manova1(X,g) return the same p-value.
Now to get to my question :) I wish to do the same as function manova1 does but on repeated measures model (https://www.mathworks.com/help/stats/repeatedmeasuresmodel-class.html) defined with function fitrm (https://www.mathworks.com/help/stats/fitrm.html#inputarg_modelspec) and then use manova method (https://www.mathworks.com/help/stats/repeatedmeasuresmodel.manova.html) on this model. I have already succeded definig model and than use ranova method (https://www.mathworks.com/help/stats/repeatedmeasuresmodel.ranova.html) on it but as the table has to have the same number of rows for each column I had to add NaN values for missing data and again lose the information. The repeated model I defined trying to use manova method later is:
names1 = cell(size(a,1), 1); names1(:) = {'x1'}; names2 = cell(size(b,1), 1); names2(:) = {'x2'}; names3 = cell(size(c,1), 1); names3(:) = {'x3'}; names = [names1;names2;names3];
t = table(names,X,... 'VariableNames',{'names','X'});
Meas = table([1]','VariableNames',{'Measurements'});
rm = fitrm(t,'X~names','WithinDesign',Meas);
manovatbl = manova(rm)
But the p-values in manovatbl are all NaN. Could you please help me change this rm model so that I will get the same p-value with manova(rm) and manova1(X,g).
Many thanks and sorry for any grammar mistakes!
0 件のコメント
回答 (1 件)
Aditya
2025 年 2 月 8 日 10:24
Hi Jan,
To perform a repeated measures ANOVA with unequal sample sizes without losing data, you can consider reshaping your data and using a more flexible approach. The issue with using fitrm and manova in MATLAB is that they require complete data for each subject across all conditions. Since your data have unequal sample sizes, you need a method that can handle this appropriately.
Here is the example code for the same.
% Sample data
a = rand(300,1);
b = rand(700,1);
c = rand(500,1);
X = [a; b; c];
g = [ones(size(a,1),1); 2*ones(size(b,1),1); 3*ones(size(c,1),1)];
% Create a table for the data
t = table(X, g, 'VariableNames', {'Value', 'Group'});
% Fit a linear mixed-effects model
lme = fitlme(t, 'Value ~ Group');
% Display the ANOVA table
anova(lme)
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!