I'm doing a logistic regression in R and I'd like to know how to select the dependent and independent variables,

Logistic regression is done when the dependent variable of interest should be 1 ( like disease = 1), 0 means no disease.

the independent variables of interest should be 1 if they are causative of the disease, like smoking 1, if smoking is 0, than there is no smoking.

What if we are asked to look at 0's of the dependent variable ( target) , do we need to transform 0's to 1 in the dataset before conducting the glm ?

more precisely,

Situation 1
If the target variable should be 1 independent variables should be 0'es

do I need to change all 0'es of the independents variables to 1 ( and all 1's to 0's) to correctly interpret the model results ?

(I've tried to modify that independent variable from 0 to 1, here are the results:

(when I left the 0 as is of the independent variable):

Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.9383 0.2780 -3.375 0.000739 ***
vx1 -0.4888 0.3343 -1.462 0.143628
vx2 -13.6278 882.7434 -0.015 0.987683

When I modify all 0's of the independent variable to 1's ( and vice versa for their respective 1's):

Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.4271 0.1856 -7.690 0.0000000000000148 ***
vx_m 0.4888 0.3343 1.462 0.144

there is no second line vx_m is the only variable ...?

Situation 2
If the outcome variable should be 0 independent variables should be 0'es

same question here, do I need to transform all 0'es to 1 ( and 1's to 0's ) of both independent and dependent variables in an intermediary dataset to correctly run the model ? more precisely the dependent variable, how the results will look like ?


1 Answer 1


The coding of variables for the logistic regression is simply a matter of convenience. You just have to be careful to interpret the intercepts and slopes in a way that corresponds to your choice of coding.

It's certainly conventional, with a binary outcome, to code the outcome of primary interest as 1 and the other outcome as 0. But there's no need to do so. In that conventional coding you are modeling the log-odds of the outcome of primary interest. But you could just as easily reverse the outcome coding, in which case you are modeling the log-odds of the other outcome.

With respect to coding of binary predictors, remember that the intercept represents the estimated outcome (log-odds in logistic regression) when all categorical predictors are at their baseline levels and all continuous predictors are at 0. So for smoking history, if you code non-smoking as 0 then the intercept represents the log-odds for a non-smoker, and the slope for smoking history is the change in log-odds for a smoker. If you reverse the coding of smoking history, then you reverse the interpretation. With smoking coded as 0 the intercept is the log-odds for a smoker and the slope will be the change in log-odds for a non-smoker. Predictions from the model would be the same with either coding.

I suspect that some data-coding or modeling error led to the loss of a variable in the summary of your second model.

  • $\begingroup$ 1) Thanks for you quick response, how to do it in practice ? to not lose what is 0 and what is 1 in independent variables ? and how can i know what is vx1 ( 0 or 1) and what is vx2 ( 0 or 1) it's a simple example here, but if I have many variables it will be easy to be lost ..., the first is the unchanged model, the second was modified as explained.. 2) and the same way how will change the target if it was 0 and I'll modify it to 1 ( ps: in the example the target was not modified and is correct = 1) Thank you for this. $\endgroup$
    – HappyMan
    Aug 16, 2020 at 15:11
  • 1
    $\begingroup$ @HappyMan to avoid errors I'd recommend staying with the original data coding, whatever that was, and just interpret the intercepts and slopes in a way that corresponds with that coding. Also, use descriptive labels for predictors and for their values. For example, instead of trying to code smoking history yourself as 0 or 1, use a logical predictor "smoker" with FALSE/TRUE values, or use a categorical predictor "smoking history" with levels "non-smoker" and "smoker." Most software can silently transform those to 0/1 for calculations, then transform back into your descriptive terms. $\endgroup$
    – EdM
    Aug 16, 2020 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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