5
$\begingroup$

I' m asking this question out of sheer curiosity, my teacher was not able to explain it.

If I'm using logistic regression with categorical variables they are coded like {1,2,3}. I guess it wouldn't change my results if I used {4,5,6}. But what if linearity of coding wasn't kept? (say {4,10,99})? What I deal with is just the way of coding factor variables but is it possible that the statistical inference could be "distorted" this way? Or, worst case scenario, would I be able to draw nonsense conclusions from categorical data just because they are coded in some way?

$\endgroup$
11
$\begingroup$

The point is that you don't code levels of categorical variables as 1,2,3 even if you call them that. You code them using dummy variables, e.g. $$\begin{array}{l c c} &x_1&x_2\\ \text{level 1} &0 & 0\\ \text{level 2} &1 & 0\\ \text{level 3} &0 & 1\\ \end{array}$$ so that when the linear predictor is given by $$\eta = \beta_0 +\beta_1 x_1 +\beta_2 x_2$$ $\beta_0$ is the log odds for level 1, $\beta_1$ is the log odds ratio between level 2 & level 1, & $\beta_2$ is the log odds ratio between level 3 & level 1. Different coding schemes can be used (see here), changing the interpretation of the coefficients but not materially changing the model (i.e. the same predictor values give the same predicted response).

| cite | improve this answer | |
$\endgroup$
5
$\begingroup$

If your software treats a factor variable with factor levels 1, 2, 3 as numeric, your model and your predictions will be garbage, simply because the difference (on the link scale) between groups 1 and 3 will be fitted to be double the difference between groups 1 and 2, which will usually not make sense.

So: tell your software that 1, 2, 3 are factors. Better still, use A, B, C. No honest software will misunderstand A, B, C as numeric.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.