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)