2

I am running some regressions in Matlab. My first three regressions are:

tbl1=table(Y1,X1); 
mdl1=fitlm(tbl1,'Y1~X1'); 
mdl12=fitglm(tbl1,'Y1~X1','Distribution','binomial','link','probit'); 
mdl13=fitglm(tbl1,'Y1~X1','Distribution','binomial'); 
  • Y1 is my dependent variable, it’s binary, it only takes the values 0 or 1.
  • X1, the independent variable, is a 1-column logical variable. It is a dummy, it only takes the values of 1 and 0 too.

These 3 different models are working.

I previously built groups of dummies to control for different effects (e.g: year, industry, number of employees, etc) for example:

group1=cell2mat(A(:,5));
[~, ~, ugroup1] = unique(group1)
D1=dummyvar(ugroup1);
D1(:,1)=[0];                       %Define reference group
D1=logical(D1);

Or

group2=cell2mat(A(:,6));
x2 = [0 10 20 25 30 35 40 45 50 55 60 70 100 300];
 [n2, idx2] = histc(group2, x2);
D2 = bsxfun(@eq, idx2, 1:length(x2)-1);
D2(:,1)=[0];

In total I have 94 dummies, grouped in 4 different logical arrays (D1-48 levels, D2-13 levels, D3- 6 levels and D4-27 levels).

What I am trying to do now is to add them to the regressions above:

tbl1=table(Y1,X1,D1,D2,D3,D4); 
mdl1=fitlm(tbl1,'Y1~X1+D1+D2+D3+D4'); 
mdl12=fitglm(tbl1,'Y1~X1+D1+D2+D3+D4','Distribution','binomial','link','probit'); 
mdl13=fitglm(tbl1,'Y1~X1+D1+D2+D3+D4','Distribution','binomial'); 

But I always get errors :

1.Error using classreg.regr.FitObject/selectVariables (line 402)
Predictor variables must be numeric vectors, numeric matrices, or categorical vectors.

2.Error in classreg.regr.TermsRegression/selectVariables (line 370)
            model = selectVariables@classreg.regr.ParametricRegression(model);

3.Error in classreg.regr.FitObject/doFit (line 217)
            model = selectVariables(model);

I have been trying different options like changing the type of variable or adding for exampletbl1.D1=nominal(D1); but it always gives error. I guess it must be related to the way I 'introduce' the dummy groups.

Could someone please help me? Thank you.

I tried this (all variables were changed to doubles):

Y=[Y1];
x=[X1 D1 D2 D3 D4];
mdl23=fitglm(x,Y,'Distribution','binomial');

It works but I am not sure it is right. I get this warning:

Warning: Iteration limit reached.

I don't understand why since I reduced a lot my dummy levels.

Community
  • 1
  • 1
user3557054
  • 219
  • 2
  • 11

1 Answers1

0

You have to make sure that all the inputs to table() are column vectors. If you give it row vectors, it'll accept them, but then fitglm() and fitglme() will fail because they expect column vectors.

robertjlooby
  • 7,160
  • 2
  • 33
  • 45
Alik
  • 1