# ranova with two within factors

27 visualizaciones (últimos 30 días)
RP el 15 de Jun. de 2019
Comentada: Jeff Miller el 23 de Abr. de 2021
Hello everyone,
I have a question about how to do a repeated measures anova in Matlab. I have data from 20 people who were tested in 4 conditions each: treatment A pre test, treatment A post test, treatment B pre test, treatment B post test. I want to use time and treatment as factors. However I only managed an anova with one factor. Here's what I got so far:
datatable = cell2table(struct2cell([pre.A, pre.B, post.A, post.B]'));
datatable.Properties.VariableNames = {'pre_A','pre_B','post_A','post_B'};
rm = fitrm(datatable, 'pre_A,pre_B,post_A,post_B~1','WithinDesign',[1:4]);
ranovatable = ranova(rm)
How do I introduce the treatment as a second within factor? I read the documentation but did not find anything I could make use of. Thank you so much in advance!
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Jeff Miller el 16 de Jun. de 2019
Editada: Jeff Miller el 24 de Nov. de 2020
datatable.Properties.VariableNames = {'pre_A','pre_B','post_A','post_B'};
% When you have more than one repeated-measures factor, you must set up a table
% to indicate the levels on each factor for each of your different variables.
% Here is the command you need for this case:
WithinStructure = table([1 1 2 2]',[1 2 1 2]','VariableNames',{'PrePost','TreatAB'});
% The 4 different rows of the WithinStructure table correspond to the 4 different
% columns, 'pre_A','pre_B','post_A','post_B', respectively, in your data table.
% Each 'pre_A','pre_B','post_A','post_B' column is coded as 1/2 on the PrePost factor
% and as 1/2 on the TreatAB factor.
% Indicate that the 1's and 2's of WithinStructure are category labels
% rather than regression-type numerical covariates:
WithinStructure.PrePost = categorical(WithinStructure.PrePost);
WithinStructure.TreatAB = categorical(WithinStructure.TreatAB);
% Now pass the WithinStructure table to fitrm so that it knows how the different
% columns correspond to the different levels of the repeated-measures factors.
rm = fitrm(datatable, 'pre_A,pre_B,post_A,post_B~1','WithinDesign',WithinStructure);
% Finally, you need to specify the repeated-measures factors again when you call ranova, like this:
ranovatable = ranova(rm,'WithinModel','PrePost*TreatAB');
##### 10 comentariosMostrar 8 comentarios más antiguosOcultar 8 comentarios más antiguos
deejt el 22 de Abr. de 2021
Editada: deejt el 22 de Abr. de 2021
@Jeff Miller Thank you for the explanation!
However, when I run your code I always get multiple error messages at the code when I try to fith the Within Struct Table
I have basically the same structure with the difference that my treatment has 3 levels (a,b,c) and my condition also has 3 levels.
Do you have any idea why that can be?
These are the messages:
Error using classreg.regr.FormulaProcessor (line 385)
The model formula contains names not recognized as predictor or response names.
Error in fitrm (line 77)
s = RepeatedMeasuresModel.fit(ds,model,varargin{:});
Error in RM_Anova (line 10)
rm = fitrm(dT,
'A1,A2,A3,B1,B2,B3,C1,C2,C3~1','WithinDesign',dWithinStructure);
Jeff Miller el 23 de Abr. de 2021
No, sorry, I can't tell from this info. I suggest you start a new question and provide more explanation about the design, as well as all the relevant code.

Iniciar sesión para comentar.

### Categorías

Más información sobre Repeated Measures and MANOVA en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by