how to calculate three way repeated anova?
27 ビュー (過去 30 日間)
古いコメントを表示
how to perform 3 way repeated anova in Matlab? I have two levels in stress , 2 levels in performers , and 2 levels in feedback as reward / penlaty. Stress and performers are between subject factor and the feedback is within subject factor. I want to apply three way repeated anova ? The data is attached.
1 件のコメント
Ayush
2023 年 3 月 1 日
To perform a three-way repeated measures ANOVA in Matlab with stress and performers as between-subject factors and feedback as the within-subject factor, you can use the "fitrm" and "ranova" functions from the Statistics and Machine Learning Toolbox.
You can read more about them from the following links:
回答 (1 件)
Scott MacKenzie
2023 年 5 月 1 日
編集済み: Scott MacKenzie
2023 年 5 月 1 日
It seems you have a design with three independent variables. Two are between-subjects and one is within-subjects:
- Stress (between-subjects)
- Performance (between-subjects)
- Feedback (within-subjects)
Below is a script for a three-way ANOVA for your data.
Personally, I don't like the table created by MATLAB's ranova function, so I'm also including a function that creates a more conventional ANOVA output table from the ranova output. The dependent variable is just named "DV" in the table since you didn't name the variable in your question.
% load your data into data table
load(websave('data', 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1305605/data.mat'))
data.Properties.VariableNames = {'Stress', 'Performance', 'Reward', 'Penalty'};
% setup and do the three-way ANOVA
withinDesign = table([1 2]','VariableNames',{'Feedback'});
withinDesign.Feedback = categorical(withinDesign.Feedback);
rm = fitrm(data,'Reward-Penalty ~ Stress*Performance','WithinDesign',withinDesign);
AT = ranova(rm, 'WithinModel', 'Feedback');
% output a conventional ANOVA table from ranova output
disp(anovaTable(AT, 'DV'));
% -------------------------------------------------------------------------
% function to create a conventional ANOVA table from the overly-complicated
% anova table created by the ranova function
function [s] = anovaTable(AT, dvName)
c = table2cell(AT);
% remove erroneous entries in F and p columns
for i=1:size(c,1)
if c{i,4} == 1
c(i,4) = {''};
end
if c{i,5} == .5
c(i,5) = {''};
end
end
% use conventional labels in Effect column
effect = AT.Properties.RowNames;
for i=1:length(effect)
tmp = effect{i};
tmp = erase(tmp, '(Intercept):');
tmp = strrep(tmp, 'Error', 'Participant');
effect(i) = {tmp};
end
% determine the required width of the table
fieldWidth1 = max(cellfun('length', effect)); % width of Effect column
fieldWidth2 = 57; % width for df, SS, MS, F, and p columns
barDouble = repmat('=', 1, fieldWidth1 + fieldWidth2);
barSingle = repmat('-', 1, fieldWidth1 + fieldWidth2);
% re-organize the data
c = c(2:end,[2 1 3 4 5]);
c = [num2cell(repmat(fieldWidth1, size(c,1), 1)), effect(2:end), c]';
% create the ANOVA table
s = sprintf('ANOVA table for %s\n', dvName);
s = [s sprintf('%s\n', barDouble)];
s = [s sprintf('%-*s %4s %11s %14s %9s %9s\n', fieldWidth1, 'Effect', 'df', 'SS', 'MS', 'F', 'p')];
s = [s sprintf('%s\n', barSingle)];
s = [s sprintf('%-*s %4d %14.5f %14.5f %10.3f %10.4f\n', c{:})];
s = [s sprintf('%s\n', barDouble)];
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Repeated Measures and MANOVA についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!