Error when introducing dummy variables in a regression

2 visualizzazioni (ultimi 30 giorni)
Maria
Maria il 27 Ago 2014
Commentato: Maria il 27 Ago 2014
I am running the following regressions in Matlab:
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 alos 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 example
tbl1.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.

Risposte (0)

Categorie

Scopri di più su Linear and Nonlinear Regression in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by