# How would one impute missing values for a Discrete variable?

How would one imputing missing values (without using the mode) for a discrete variable, e.g. a variable corresponding to a count.

Apart from the methods @Media mentioned, here are some more:

### Imputing with info from other variables

This method is to create a (multi-class) model based on target variable. So that missing values would be predicted.

The steps are likely to be:

• Subset data without missing value in the variable you want to impute
• Machine learning on the data with predict model
• Predict on data with the missing value from model created

### Clustering

Whether missing values are mainly related to a combination of variables? Unsupervised methods may help here.

An example using randomForest: https://stats.stackexchange.com/questions/107530/using-cluster-information-in-multiple-imputation

### Domain Knowledge

If we known that the reason for missing value, we can assign the missing value to a proper level. For example, a survey data are collected from web where given choices are not applicable for some cases, hence leave blank. In this case, it would be better to leave as a separate value.

### Implementation

There are some R package can impute the data for you;

• MICE
• Amelia
• missForest
• Hmisc
• mi

https://www.analyticsvidhya.com/blog/2016/03/tutorial-powerful-packages-imputing-missing-values/

• This method is to create a (multi-class) model based on target variable. So that missing values would be predicted. Could you elaborate on this further ? Whether missing values are mainly related to a combination of variables? Unsupervised methods may help here. could you give an example of an unsupervised method, and the way to which it would be used to impute values ? Thanks.
– Gale
Mar 1 '18 at 11:18
• @Gala, answer edited per comment. Mar 1 '18 at 15:14

It depends, if you have the distribution of that feature, you can take the marginal distribution over that feature which its interpretation is to use the expected value of that feature. If you don't have the distribution you can take the mean of the sample in hand of those samples which have value for that feature and add the mean for those which don't have. Another solution is to separate the data of each class and find the mean of the feature of those data samples having the value and putting the mean for each entry of the corresponding class which does not have value in that entry.

•  If you don't have the distribution you can take the mean of the sample in hand of those samples which have value for that feature and add the mean for those which don't have. Sorry, not quit following on what you mean by this. Can you reiterate ? Also, since it is a discrete variable, would imputing using the mean be a valid approach, given the values of the feature are integers ? Thanks
– Gale
Mar 1 '18 at 11:53
• @Gale I've seen your comment late. Do you still have problem? Mar 2 '18 at 13:30
• Just wanted to have a better understanding of your response :-)
– Gale
Mar 2 '18 at 14:14
• The problem of discrete value can be solved by just finding the nearest integer value. When you are speaking about a sample, you can find the statics of the sample. Mean and expected value are different. Whenever you have the distribution, you can find the exact value of the mean of the population. But in real world you just have sample. For sample you take the average of the features that can be measured and by using some methods you extend them to the entire population. Tell me if you need more explanation. Mar 2 '18 at 14:24