MATLAB Answers

Error when running a repeated measures ANOVA

5 views (last 30 days)
pablo dopico
pablo dopico on 23 Nov 2020
Commented: pablo dopico on 24 Nov 2020
Hello, I need to run a repeated measure ANOVA with three independent factors, but I'm struggling to make my code work even with just one factor.
Below is my code.
words is a matrix with columns corresponding to patient IDs (integers 1-205). Vowel, Treatment, and Test are all factors, but are replaced with a number (ex. Test can take the value 1, 2, or 3). Test is the repeated measure "time" variable. MD is the dependent outcome variable.
I tried running my ANOVA without including other factors at first, following along with other examples, I've seen. I keep getting the error:
"Error using RepeatedMeasuresModel/set.WithinDesign (line 1235) Specified design has 3 points; 1 required. "
I guess I don't understand the role of WithinDesign very well. Could someone help me out a bit?
Thank you!
words = array2table(words);
stories = array2table(stories);
words.Properties.VariableNames(1:5) = {'ID','Vowel','Treatment','Test','MD'};
withinDsgn = table((1:3)','VariableNames',{'Test'});
wordsrm = fitrm(words, 'MD~ID*Test', 'WithinDesign', withinDsgn);

  0 Comments

Sign in to comment.

Accepted Answer

Jeff Miller
Jeff Miller on 23 Nov 2020
I'm pretty sure fitrm expects all of the data from a single patient to be on one row of the input data table (e.g., words)--at least by default, maybe there is some way around this. So, for your example with 3 tests, it would expect 3 separate columns of data, say Test1, Test2, Test3, and a command like
wordsrm = fitrm(words,'Test1-Test3 ~ ID','WithinDesign', withinDsgn)
Your fitrm command only specified one score (MD), so fitrm thought the WithinDesign 'required' only one condition per patient, and it was confused because your WithinDesign specifies 3 conditions.
Additional repeated measures factors would multiply the number of columns to the left of the '~' in the model statement.

  3 Comments

pablo dopico
pablo dopico on 24 Nov 2020
Thank you!
So for additional factors I would need a column for every factor-time? Ex. Vowel1*Treatment1*Test1 as one column, then Vowel1*Treatment1*test2, etc?
So with multiple factors this would be:
wordsrm = fitrm(words, 'Column1-ColumnN ~ ID', 'WithinDesign',withinDsgn)
wordsanova = ranova(wordsrm, 'WithingDesign', withinDsgn)
Jeff Miller
Jeff Miller on 24 Nov 2020
Right. And you need to specify that the variables of WithinDesign are categorical. The example here may help.
pablo dopico
pablo dopico on 24 Nov 2020
Thanks so much for your help, I'll give this a shot, i think I understand this much better now.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by