Repeated measures ANOVA with 2 variables with different levels

Hi, I am trying to run a 2 way RMANOVA on this data called RMANOVA_Table_Analysis. I have also attached this dataset.
I am trying to get the main effect of background, color and the interaction between them. This is what I tried, looks like I am making an error in creating the repeated measures model.
Any pointers on how to do this correctly, would be much appreciated!

 采纳的回答

Change
rm = fitrm(dv, 'uniR - texB ~ 1 ', 'WithinDesign', withinDesign);
to
rm = fitrm(dv, 'uniR-texB ~ 1 ', 'WithinDesign', withinDesign);
Apparently, the fitrm function doesn't like the spaces on each side of the dash.

3 个评论

Thank you, Scott!! Removing the space made it work. Rookie mistake.
Another question:
This is the code I use to create the ANOVA table.
[file,path] = uigetfile('*.xlsx');
Q = readtable(file);
dv = array2table(reshape(RMANOVA_Table_Analysis.mean_final_offset, num_subj, []));
% codes for column names: uni = uniform, tex = textured, R=red, G=green B=blue
dv.Properties.VariableNames = {'uniR','uniG','uniB', 'texR', 'texG', 'texB'};
% create the within-subjects design
withinDesign = table([1 1 1 2 2 2]',[1 2 3 1 2 3]','VariableNames',{'Background','Color'});
withinDesign.Background = categorical(withinDesign.Background);
withinDesign.Color = categorical(withinDesign.Color);
% create repeated measures model
rm = fitrm(dv, 'uniR-texB ~ 1 ', 'WithinDesign', withinDesign);
% perform anova (remove semicolon to view table generated by ranova)
AT = ranova(rm, 'WithinModel', 'Background*Color');
If I replace
rm = fitrm(dv, 'uniR-texB ~ 1 ', 'WithinDesign', withinDesign);
with
rm = fitrm(dv, 'uniR-texB ~ Background*Color+Background+Color ', 'WithinDesign', withinDesign)
I'd think I would get a similar response. But instead I get an error instead (below):
rm = fitrm(dv, 'uniR-texB ~ Background*Color+Background+Color ', 'WithinDesign', withinDesign)
Error using classreg.regr.FormulaProcessor (line 385)
The model formula contains names not recognized as predictor or response names.
Error in classreg.regr.MultivariateLinearFormula (line 47)
f = f@classreg.regr.FormulaProcessor(varargin{:});
Error in RepeatedMeasuresModel.fit (line 1312)
formula = classreg.regr.MultivariateLinearFormula(model,varNames);
Error in fitrm (line 77)
s = RepeatedMeasuresModel.fit(ds,model,varargin{:});
Would you know why this is the case?
@MM, you're welcome. In specifying the modelspec for fitrm, the between-subjects variables are placed on the right-hand side of the tilde symbol. Your design does not have any between-subjects variables, so "1" is used on the right-hand side of tilde in the modelspec. In your modified code, you are trying to position the within-subjects variables (Background, Color) as between-subjects variables. That's the reason for the error.
In your original code (with the correction I noted), you will get three effects: the main effects for Background and Color and the Background x Color interaction effect. From your question, I think that's your main objective, right? So I'm not sure what you are trying to do in the second version of fitrm.
BTW, the effect of Color on mean_final_offset was statistically significant, F(2,22) = 4.006, p = .0328. The other two effects were not statistically significant.
Thank you for explaining! Makes sense why I get the error.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心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!

Translated by