Error with fitrm - error using setdiffR2012a

조회 수: 7 (최근 30일)
Irene Torres
Irene Torres 2018년 6월 30일
편집: Walter Roberson 2025년 2월 3일
Hi,
I am trying to apply the function fitrm (with MATLAB2015b) but it seems not to be working even with the documentation's example. It gives me always the same error message and I have not found the way to solve this.
This is the code and the error:
load fisheriris
t = table(species,meas(:,1),meas(:,2),meas(:,3),meas(:,4),...
'VariableNames',{'species','meas1','meas2','meas3','meas4'});
Meas = table([1 2 3 4]','VariableNames',{'Measurements'});
rm = fitrm(t,'meas1-meas4~species','WithinDesign',Meas)
Error using setdiff>setdiffR2012a (line 218)
Inputs A and B must be matrices with the same number of columns in the 'rows'
case.
Error in setdiff (line 135)
[varargout{1:nlhs}] = setdiffR2012a(varargin{1:2},logical(flaginds(1:3)));
Error in classreg.regr.FormulaProcessor>createTerms (line 669)
addTerms = setdiff(addTerms,removeTerms,'rows');
Error in classreg.regr.FormulaProcessor/processFormula (line 593)
f.terms = sortTerms(createTerms(f,t,s,lp,varNames));
Error in classreg.regr.FormulaProcessor (line 390)
f = processFormula(f,varNames);
Error in classreg.regr.MultivariateLinearFormula (line 46)
f = f@classreg.regr.FormulaProcessor(varargin{:});
Error in RepeatedMeasuresModel.fit (line 1297)
formula = classreg.regr.MultivariateLinearFormula(model,varNames);
Error in fitrm (line 67)
s = RepeatedMeasuresModel.fit(ds,model,varargin{:});
Is there anybody who encountered the same problem and knows how to solve it?

답변 (1개)

Aditya
Aditya 2025년 2월 3일
Hi Irene,
The error you're encountering when using the fitrm function in MATLAB is likely due to a mismatch in the expected input format, particularly with the way the repeated measures design is specified. Let's go through the example you provided and ensure that the code aligns with what fitrm expects.
Following is a code smaple without any errors:
% Load the data
load fisheriris
% Create a table with the measurements and species
t = table(species, meas(:,1), meas(:,2), meas(:,3), meas(:,4), ...
'VariableNames', {'species', 'meas1', 'meas2', 'meas3', 'meas4'});
% Define the within-subjects design
Meas = table([1 2 3 4]', 'VariableNames', {'Measurements'});
% Fit the repeated measures model
rm = fitrm(t, 'meas1-meas4 ~ species', 'WithinDesign', Meas);

카테고리

Help CenterFile Exchange에서 Repeated Measures and MANOVA에 대해 자세히 알아보기

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by