Can I do a repeated-measures three-way ANOVA with 2 within and one between variable?

36 views (last 30 days)
Is it possible to perform a three-way ANOVA with repeated-mearues with 2 within variables and 1 between variable?
The two within variables are time (I have measurements from different days) and frequency (I used different frequencies in the measurements). These are repeated-measures. The between variabel is the group allocations (treatment or no treatment).
If so how would I design the table to fit the repeated-measures model to be able to then use the ranova function. Do I use one column or one row for each subject.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 15 Jun 2021
Edited: Scott MacKenzie on 15 Jun 2021
Yes. Here's an example script I used recently for such a design. The within-subjects factors are Layout (2 levels) and Trial (5 levels). The between-subjects factor was Group (2 levels). I'm attaching the data file as well.
T = readtable('softkeyboard-h12x10b.txt');
T.Properties.VariableNames = {'o1','o2','o3','o4','o5','q1','q2','q3','q4','q5', 'Group'};
withinDesign = table([1 1 1 1 1 2 2 2 2 2]',[1:5 1:5]','VariableNames',{'Layout','Trial'});
withinDesign.Layout = categorical(withinDesign.Layout);
withinDesign.Trial = categorical(withinDesign.Trial);
rm = fitrm(T,'o1-q5 ~ Group','WithinDesign',withinDesign);
AT = ranova(rm,'WithinModel','Layout*Trial');
  4 Comments
Marleen
Marleen on 24 Mar 2023
Hi,
First of all, thank you very much for your answers, it helped me a lot already. However, I am getting stuck at some point.
I have a similar design as ms. Evers, where I have two within variables and none between. I tested the brain activity of mice in different hypoxialevels, and want to compare the correlation between seeds within the same cluster and between different brainclusters. So my "within" variables are the hypoxia levels that I tested the mice in (HLevel) and whether or not the seedpairs were within the same area (Area).
I was able to follow all the steps and everything works well. However, I saw online that one of the assumptions that needs to be met when doing an rm anova is sphericity, and that that can be checked with the mauchly function in matlab. The sphericity in my case does not hold, so I have to do an epsilon correction. However, I cannot give the epsilon correction the interaction between my "within" variables, and am also unsure about the answers it gives. Does the epsilon function do the ranova already? Should I give the ranova function my epsilon values?
Here is my code:
conditions = table(reshape(repmat({'with', 'betw'}, [5 1]), 10, 1),...
reshape([HypoxiaLevels HypoxiaLevels], 10,1),'VariableNames',{'Area','HLevel'});
conditions.Area = categorical(conditions.Area);
conditions.HLevels = categorical(conditions.HLevel);
%we have no between factors, so ~1. Two within factors: 1.within/between
%areas and 2. hypoxia level.
rm = fitrm(wb, 'w1-b5~1', 'WithinDesign', conditions);
mauchlytbl = mauchly(rm); %sphericity does not hold, do epsilon correction
epsilontbl = epsilon(rm);
AT = ranova(rm, 'WithinModel','Area*HLevel');
I also attached the .mat file of my data.
Thanks in advance
Brennan
Brennan on 25 Jan 2024
Hello,
I have an extremely similar dataset with 1 between subjects factor (group) and 2 within subjects factor (5 different variables collected at timepoint1 and timepoint2). I have set it up exactly as you have above and my result table indicates a significant p-value for Group:Timepoint:Variable. However, I am now interested in finding which of the 5 variables show significant difference by the group and visit interaction. Such as:
T = multcompare(rm,'Variable','By','Group','By','Timepoint');
or
T = multcompare(rm,'Variable','By','Group*Timepoint');
Neither of which works. Any help on this last step would be appreciated. Thanks!

Sign in to comment.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!