# Logistic Regression using dummy variables in MATLAB

I have a model where categorical (mutually exclusive) variables predict bankruptcy. Chi-square is significant. How can I code a logistic regression model in MATLAB that proves that some of these variables explain the bankruptcies better.

There are 4 variables: which implies 3 dummy variables.

X = [  0 0 0
0 1 0
0 0 0
0 0 1
0 0 1
1 0 0
1 0 0 ......... ] ;
Y = [1 0 0 1 1 0 0 .....]; % 1 means bankruptcy


I think I should use glmfit (from http://matlabdatamining.blogspot.com/2009/03/logistic-regression.html) but I wasn't sure if using dummy indicators would require any additional interpretation/inputs. I use latest version and have Statistics and Optimization Toolbox.

• This question appears to be off-topic because it is about MATLAB code. Please take this kind of question to Stack Overflow or a MATLAB forum. Commented Mar 7, 2014 at 17:49
• @NickCox, it does belong on SO, but we can migrate it for the OP. Commented Mar 7, 2014 at 18:58
• People on SO often object to questions without (serious) code, as when the OP just is asking generally about some program, command or function, but I am happy to let this question have its chance. Commented Mar 7, 2014 at 19:03
• Isn't there a statistical question lurking here about the appropriate way to code categorical variables for making [some kind of as-yet unexplained] comparisons? If there is, Maddy, then could you please edit your question to make this emphasis more apparent and to help us understand better what you are looking for?
– whuber
Commented Mar 7, 2014 at 21:26
• @whuber @gung I'm hoping to learn 3 things here: 1. Is there intercept term the slope for the remaining variable that wasn't used in the N-1 dummies? 2. The slopes are the odds for event happening. Eg, exp(Beta1) will give me the odds for bankruptcies happening when X1 is true. exp(Beta2) will give me the odds for bankruptcies happening when X2 is true...... 3. A coding example where entire logistic regression can be interpreted. glmfit gives me stdev, betas, stderrors, p etc for training and test sets. How do I decide my model's accuracy. Thanks so much! Commented Mar 7, 2014 at 22:30

You can use glmfit and create dummy variables yourself. If you include a constant term you would want to omit one of the dummy variables.
However, as of late 2013 there is a fitglm function that can handle categorical predictors for you.