how to calculate three way repeated anova?
조회 수: 28 (최근 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!