이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Errors in Repeated Measures Model function fitrm

조회 수: 1(최근 30일)
Minahil Khan
Minahil Khan 2018년 2월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
I'm trying to run a repeated measures ANOVA on my data in MATLAB. To do this I need to make my table a RepeatedMeasuresModel using fitrm. I've attached the .mat file with my table (tabn1.mat) Each participant in the trial had a value for Edge1, Edge2... until Center. Var1 is the participant's identification number. I set it as the predictor variable because I just want to do a comparison of means (compare average of everyone's edge1 values to edge2...etc)
Here's what I did:
Meas = table([1 2 3 4 5],'VariableNames',{'Measurements'});
tab1 = fitrm(tabn1, 'Edge1-Center~Var1', 'WithinDesign' Meas);
But then I get the following errors:
Error using eig
Input matrix contains NaN or Inf.
Error in RepeatedMeasuresModel>mauchlyTest (line 1922)
lam = eig(C'*S*C);
Error in (line 1370)
[this.Mauchly,this.Epsilon] = mauchlyTest(this.Cov,size(Xmat,1),rank(Xmat));
Error in fitrm (line 67)
s =,model,varargin{:});
I followed the example that Mathworks provides on their website very closely because I am not very familiar with statistics. I've also attached the example i followed.


Scott MacKenzie
Scott MacKenzie 2021년 7월 28일
편집: Scott MacKenzie 2021년 7월 28일
Here's an image of the data in this question:
The data are in the attached file, testdata.txt.
Design summary: This is a single-factor within-subjects design with six participants. The factor, or independent variable, is not named in the question, so it is given the name IV in the code below. There were six measures taken on the independent variable: Edge1, Edge2, Edge3, Edge4, and Center. The dependent variable is named Measure.
Below is the code to analyse the data using the ranova function. As seen in the anova table below, the effect of IV on Measure was not statistically significant: F(4,20) = 2.675, p > .05.
The code finishes with a function I wrote that generates a conventional anova table from the overly-complex and confusing anova table generated by the ranova function.
% data from question (1 within-subjects factor with 5 levels, 6 participants)
T = readtable('testdata.txt'); % 6x6
T.Properties.VariableNames = {'Participant' 'Edge1' 'Edge2' 'Edge3' 'Edge4' 'Center'};
% create the within-subjects design
withinDesign = table([1 2 3 4 5]','VariableNames',{'IV'});
withinDesign.IV = categorical(withinDesign.IV);
% create the repeated measure model and do the anova
rm = fitrm(T,'Edge1-Center ~ 1','WithinDesign',withinDesign);
AT = ranova(rm,'WithinModel','IV'); % remove comma to see ranova's table
% output a conventional anova table
disp(anovaTable(AT, 'Measure (units)'));
ANOVA table for Measure (units) ======================================================================== Effect df SS MS F p ------------------------------------------------------------------------ Participant 5 0.00204 0.00041 IV 4 0.00073 0.00018 2.675 0.0618 Participant(IV) 20 0.00136 0.00007 ========================================================================
% ---------------------------------------------------------------------
% Scott's function to create a conventional ANOVA table from the
% overly-complicated and confusing anova table created by the ranova
% function.
function [s] = anovaTable(AT, dvName)
c = table2cell(AT);
% remove erroneous entries in F and p columns
for i=1:size(c,1)
if c{i,4} == 1
c(i,4) = {''};
if c{i,5} == .5
c(i,5) = {''};
% use conventional labels in Effect column
effect = AT.Properties.RowNames;
for i=1:length(effect)
tmp = effect{i};
tmp = erase(tmp, '(Intercept):');
tmp = strrep(tmp, 'Error', 'Participant');
effect(i) = {tmp};
% determine the required width of the table
fieldWidth1 = max(cellfun('length', effect)); % width of Effect column
fieldWidth2 = 57; % field needed for df, SS, MS, F, and p columns
barDouble = sprintf('%s\n', repmat('=', 1, fieldWidth1 + fieldWidth2));
barSingle = sprintf('%s\n', repmat('-', 1, fieldWidth1 + fieldWidth2));
% re-organize the data
c = c(2:end,[2 1 3 4 5]);
c = [num2cell(repmat(fieldWidth1, size(c,1), 1)), effect(2:end), c]';
% create the ANOVA table
s = sprintf('ANOVA table for %s\n', dvName);
s = [s barDouble];
s = [s sprintf('%-*s %4s %11s %14s %9s %9s\n', fieldWidth1, 'Effect', 'df', 'SS', 'MS', 'F', 'p')];
s = [s barSingle];
s = [s, sprintf('%-*s %4d %14.5f %14.5f %10.3f %10.4f\n', c{:})];
s = [s, barDouble];

Community Treasure Hunt

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

Start Hunting!

Translated by