# Which glm algorithm to use when predictors are numerical as well as categorical?

I just need a direction on which regression algorithm (preferably glm or similar) algorithm to use when the predictor variables are a mix of numerical and categorical variables. The output is numerical for the time being but in future, I need to extend this for categorial output also.

My input columns are in the the format given below:

preNum1 predNum2 ......predCat1 predCat2 ....ResponseVar

Edit: I am trying to predict the amount of 'Bilirubin' (here, the response variable), depending on patients' data. We have patients's lab results such as glucose, blood pressure, etc etc as numerical predictor values and the patients' disease history (diabetes,and other diseases) as categorical predictors. I converted all the categorical variables (they are diseases such as diabetes, high BP, etc) into 0 and 1 (0 representing that it is not present, 1 representing it to be present.) After this I applied GLM on this. I am wondering if my approach is correct or not?

• Could you be more specific about your model? Are these categorical variables (diseases) predictors or outcomes? What software did you use to calculate the GLMs? What was the input command? Commented May 13, 2013 at 14:21
• @COOLSerdash, Thanks for reply. please see the edited OP Commented May 13, 2013 at 14:30
• Your approach seems fine. It's a simple linear model and can be fitted with ordinary least squares. Categorical responses (outcome/dependent variables) create all sorts of problem addressed with other methods but categorical predictors do not require anything else as such.
– Gala
Commented May 13, 2013 at 14:51
• @GaëlLaurans, I was more concerned with converting the categorical predictors into zeros and ones. Thanks for your insight Commented May 13, 2013 at 15:19
• @user1140126: Even if you are unaware of it: internally, the software converts categorical variables automatically into dummy variables (0,1): in R with the command as.factor and in Stata with the i-Prefix. Commented May 13, 2013 at 15:37

When your dependent variable is binary ($1$ vs. $0$, "dead" vs. "alive"), the you might use logistic regression which is a glm with a binomial error distribution and a logit link function. When your dependent variable is ordinal (e.g. "bad"> "good" > "best"), you can use ordinal logistic regression. For a nominal (e.g. transportation: "walk", "car", "bicycle") dependent variable, you can use multinomial logistic regression.

EDIT

Your approach to convert the disease status into a 0,1-variable seems correct. If your outcome is continuous, you could use a GLM with a gaussian error distribution and an identity link function which is equivalent to a simple multiple regression model (OLS).

• Bilirubin I would expect to be strongly skewed, so other error families and/or links seem indicated. Commented May 13, 2013 at 14:44
• @Nick Cox: Good point. As usual, a check of the residuals (among other things) is clearly warranted. A priori, the dependent variable doesn't have to be normal for a regression with gaussian errors to be valid, but the residuals have to be. Commented May 13, 2013 at 14:51
• We agree on essentials, but the idea that you must have normal residuals is oversold. Even if the errors really are exactly normal, the residuals won't be. If the errors are (e.g.) uniform, the usual recipes will perform rather well; it's just that e.g. P-values won't be exactly trustworthy, but they never are, any way. Commented May 13, 2013 at 15:20

The algorithm used by any implementation of generalised linear models is immaterial here -- or at least if there are grounds to choose one algorithm rather than another they don't hinge on any detail you mention.

Typically you present categorical predictors to GLM commands or functions as indicator variables (dummy variables, in a common vulgar terminology).

Quite how you do this depends a little on the software, but at the most complicated you just need to calculate your indicators in advance.