mixed factor ANOVA in Matlab

7 visualizzazioni (ultimi 30 giorni)
Adam Ranson
Adam Ranson il 30 Mag 2017
Commentato: Adam Ranson il 1 Giu 2017
Hi
I'm trying to understand how to do a mixed factor ANOVA in Matlab with one within subject factor and one between subject factor. I've been trying to reproduce the analysis performed here: https://www.youtube.com/watch?v=JBoHHFvVsqw which results in a test of the effect of 'Week', 'School' and the interaction between 'Week' and 'School'. I've tried the following code so far but I'm struggling to understand the output which only partly matches the example. The help on ranova doesn't specify what the colon means when listing the terms (seems to be interaction?), and I don't understand why there is no report of the effect of School alone, or if (Intercept):Week is telling me the effect of Week alone. This is the data/code I'm working on:
% define data
dataTable = array2table([3,5,7,0;4,4,8,0;5,3,7,0;3,5,8,0;4,5,7,0;3,5,7,0;1,5,9,1;2,4,8,1;1,3,9,1;1,5,8,1;1,5,7,1;2,4,9,1]);
% convert to table format
dataTable.Properties.VariableNames = {'Week1','Week2','Week3','School'};
% define levels of within subject factor
wsVariable = table([0 1 2]','VariableNames',{'Week'});
% run ANOVA
rm = fitrm(dataTable,'Week1,Week2,Week3~School','WithinDesign',wsVariable)
ranovatbl = ranova(rm)
If there are any Mathworks employees out there, my impression is that the help on using these functions could use a few more simple examples such as this one.
Cheers
Adam
  2 Commenti
Adam Ranson
Adam Ranson il 31 Mag 2017
Update: To get the between subject main effect I have found that you can do:
ranova(rm,'WithinModel','Week');
The thing that doesn't make sense is why the F value for the within subject factor 'Week' (labelled I think as '(Intercept):Week' in the ranova output) differs from the example I cited. I have run the example in SPSS and using the 'anova_rm' function from the file exchange both of which give me the same F value as the example from youtube (https://www.youtube.com/watch?v=JBoHHFvVsqw). Here is the code to do this ANOVA using the anova_rm function:
dataTable2 = table2array(dataTable);
[p, table] = anova_rm({dataTable2(1:6,1:3) dataTable2(7:12,1:3)});
Adam Ranson
Adam Ranson il 1 Giu 2017
Answer from Mathworks Technical Support:
Thank you for contacting MathWorks Technical Support. If you change your input table so that the School column is of type "categorical" you get the same result for "(Intercept):Week". So, after you set the variable names, insert the following line:
dataTable.School = categorical(dataTable.School);
To also get the analysis of variance for the between-subject effects, use the "anova" method:
anovatbl = anova(rm);

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by