Error with fitrm - error using setdiffR2012a
6 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Aditya
on 3 Feb 2025
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);
0 Comments
See Also
Categories
Find more on Repeated Measures and MANOVA in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!