fitlme "Index exceeds matrix dimensions."

1 view (last 30 days)
Hi, I'm trying to use the new fitlme bult-in function (R2015a) and it keeps going on an error:
Index exceeds matrix dimensions.
Error in classreg.regr.LinearLikeMixedModel.makeSparseZ (line 1312)
idxr = accumarray(subs,vals(I),[],@(x) {x});
Error in LinearMixedModel/fitStandardLMEModel (line 1225)
Zs = LinearMixedModel.makeSparseZ(Z,q,lev,Gid,N);
Error in LinearMixedModel/fitter (line 822)
model.slme = fitStandardLMEModel(model);
Error in classreg.regr.FitObject/doFit (line 220)
model = fitter(model);
Error in LinearMixedModel.fit (line 2395)
model = doFit(model);
Error in fitlme (line 224)
lme = LinearMixedModel.fit(ds,formula,varargin{:});
Also, running the fnuction takes too long (the error appears after several minutes of wating) and consume a lot of RAM. This is the line I'm running:
lmm1 = fitlme(datos_tabla, 'E1_T1 ~ pred + (1|SUJ)' );

Accepted Answer

Gautam Pendse
Gautam Pendse on 19 Nov 2015
Hi Bruno,
This doesn't look like the intended behavior but it is difficult to say why you are getting that error. Could you post your data that reproduces the problem?
Gautam
  3 Comments
Gautam Pendse
Gautam Pendse on 20 Nov 2015
Hi Bruno,
Your table is of size 1-by-3 with 3 predictors. Each variable in the table is of size 1-by-N:
The error message can be improved but fitlme expects your table to be of size N-by-3 where each row represents 1 observation. In the code below, I modify your table by transposing variables and then fit the model:
%%Display the original table
test = load('tabla_export.mat');
tabla_export = test.tabla_export;
size(tabla_export)
tabla_export
% Variables in your table are of size 1-by-N. The expectation is that your
% table will have N rows and each row would represent one observation. You
% can do this by just transposing the variables in your table as shown
% below.
%%Transpose 1-by-N variables into N-by-1 variables
E1_T1 = tabla_export.E1_T1;
pred = tabla_export.pred;
SUJ = tabla_export.SUJ;
E1_T1 = E1_T1';
pred = pred';
SUJ = SUJ';
newtbl = table();
newtbl.E1_T1 = E1_T1;
newtbl.pred = pred;
newtbl.SUJ = SUJ;
%%Fit the model
rng(0,'twister')
lme = fitlme(newtbl,'E1_T1 ~ pred + (1|SUJ)','verbose',1,'startmethod','random')
Bruno Bianchi
Bruno Bianchi on 20 Nov 2015
That really works! Thank you very much, and I hope the problem to be solve in the future!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!