I have continuous variable with missing values. Missing values are of different types (indicated by special values such as 991, 992). How do I best encode my data for logistic regression? I can create separate variables for 991 and 992, but what I should use for the column with the rest of data? If I use NA, then R fails (using na.pass). If I use na.exclude then 991, 992 variables do not make any sense.

In this case, 991 represents missing value (not collected), and 992 represent not provided value (value was attempted to be collected, but response was not provided). I do not want to exclude rows with 991, 992 as these are valid inputs and I need to model response even for these rows. Also, in real-life scenario I have many such columns and removing all rows with special values would exclude vast majority of the rows.

df <- read.table(header= TRUE, text = '
x y
1 0
1 0
1 1
2 1
2 1
2 0
3 1
3 1
3 0
991 1
992 0

glm(y ~ x, df, family = binomial(), na.action = na.pass)
  • $\begingroup$ Of course it fails using na.pass, because the NAs are just sent along to the code and will propagate through all the calculations. What happens when you use na.omit, which presumably was your intention? If that succeeds, then you can turn to the deeper question of how to differentiate among the different types of missingness. $\endgroup$ – whuber Jul 31 '15 at 18:51
  • $\begingroup$ @whuber Probably I should have asked better. I know it fails and I do not complaint about it. The question is (as you correctly assumed), how do I include different types of missingness in my analysis and what value should I input to the original column instead of NA. $\endgroup$ – Tomas Greif Jul 31 '15 at 18:55
  • 1
    $\begingroup$ It's a good question, but you haven't given us the information needed to respond. Please edit your post to explain what types of missingness these codes represent and how you propose to model them. (If you don't know how to model them, that should become the question you ask.) $\endgroup$ – whuber Jul 31 '15 at 19:02

Your Answer

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

Browse other questions tagged or ask your own question.