How to properly enter categorical variables in logistic regression in Matlab

12 views (last 30 days)
Hi there,
I am running a logistic regression using glmfit with 2 continuous variables and one categorical (4 levels). I am a bit confused about how to enter the categorical variable properly? Is there a trick?
Thanks, Vishi

Answers (1)

the cyclist
the cyclist on 16 Mar 2011
The DUMMYVAR command will create an array that you can use for categorical data.
For example,
x_cat = dummyvar([1;2;3])
outputs an array for which each column corresponds to a category. You'll want to read "help dummyvar," especially the paragraph that explains that you will likely need to delete one variable that corresponds to the regression intercept.
[Hat tip to Peter Perkins for explaining this to me a while back.]

Community Treasure Hunt

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

Start Hunting!