You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG : MICEData creates new values after imputation #5254
This imputation model is supposed to impute values from other(pre-existing) observations, as I know.
It does, however, create a value that did never exist in other observations.
I used this imputation after applying LabelEnconder in Scikit-Learn.
In this process, NaN values were replaced with 0(if NaN exists) and after they were encoded by LabelEncoder, I again replaced 0 with NaN values. And then I did imputation as uploaded here.
On Mon, Sep 24, 2018 at 12:03 PM swab2000 ***@***.***> wrote:
This imputation model is supposed to impute values from
other(pre-existing) observations, as I know.
It does, however, create a value that did never exist in other
observations.
I used this imputation after applying LabelEnconder in Scikit-Learn.
In this process, NaN values were replaced with 0(if NaN exists) and after
they were encoded by LabelEncoder, I again replaced 0 with NaN values. And
then I did imputation as uploaded here.
Any suggestions about this problem?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5254>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/ACiww7K11_XatznnlgYv_IedkT8xjnCXks5ueQJmgaJpZM4W291G>
.
MICE imputation code that you built in python is based on Predictive Mean Matching(PMM), as I see. The problem is PMM process only creates imputation that already exists in observed data. For example,
X :
x1
x2
x3
1
0.6
A
4
NA
B
NA
1.4
C
2
3.8
B
3
5.2
NA
if the dataset has 3 NA values as I mentioned above, and for x1 case, the MICE algorithm based on PMM should suggest imputation for NA value in 1, 4, 2, 3. Likewise, for x3 case, NA must be imputed within A, B, C. However, MICEData(X) creates somewhat strange values that never exists in observed data, like 0.404994. Moreover, if there are several NA values in one column(variable), all the NA values are imputed by the same, not-existing, strange values.
As I mentioned before, I used LabelEncoder in scikit-learn packages for categorical variables, in the example, x3(A B C B --> 1 2 3 1). I did this because MICEData does not take 'string' or 'object' type as input. I know this is a bad idea for categorical variables and also there is few reports imputing categorical variables via Multiple Imputation. Anyway, my total framework for imputation process is as follows.
Not an imputation expert, but in an effort to help triage, looking at the code for MICEData here is what I can tell where those strange values are coming from. If I am reading the doc string for _initial_imputation it may be working not as intended.
Looking at _initial_imputation inside MICEData the docstring:
The way I interpret that statement is that the missing values in a given column will initially be set to the observed value in the column closest to the mean. But in reality it is setting it to the absolute distance from the mean, which in the sample case is 0.5 for x1.
Where as the actual values that are closest should be something as follows:
forx,yinnp.abs(df-df.mean()).idxmin().iteritems():
print('Observed Closest to Mean:',str(x), df[x].loc[y])
Not sure if MICEData was intended to be used in that manner of just taking the initial imputation, or if was intended to be run through multiple iterations as that would bring the values in range. Running just one MICE iteration would provide values in the range of the observed data.
imp.update_all()
imp.data
Again not an imputation expert so I cannot say how much effect it the initial value will have on one imputation iteration if it is indeed incorrect. My guess would be the effect depends on the actual numbers in the applicable dataset.
I appreciate your answer @jtweeder ,and it seems you are right. After several iterations by update_all(), MICEData gives me the right imputations. Thanks!
Activity
kshedden commentedon Sep 24, 2018
swab2000 commentedon Sep 25, 2018
MICE imputation code that you built in python is based on Predictive Mean Matching(PMM), as I see. The problem is PMM process only creates imputation that already exists in observed data. For example,
X :
if the dataset has 3 NA values as I mentioned above, and for x1 case, the MICE algorithm based on PMM should suggest imputation for NA value in 1, 4, 2, 3. Likewise, for x3 case, NA must be imputed within A, B, C. However, MICEData(X) creates somewhat strange values that never exists in observed data, like 0.404994. Moreover, if there are several NA values in one column(variable), all the NA values are imputed by the same, not-existing, strange values.
As I mentioned before, I used LabelEncoder in scikit-learn packages for categorical variables, in the example, x3(A B C B --> 1 2 3 1). I did this because MICEData does not take 'string' or 'object' type as input. I know this is a bad idea for categorical variables and also there is few reports imputing categorical variables via Multiple Imputation. Anyway, my total framework for imputation process is as follows.
Numerical Variables -------------------------------------------------> MICE
Categorical Variables ----------------> LabelEncoder --------------> MICE
I am not sure if the problem takes place in LabelEncoder, but this problem happens in both numerical and categorical cases.
I appreciate your prompt response and I hope you could capture the problem I explained. I cannot go further because of this problem.
jtweeder commentedon Oct 4, 2018
Not an imputation expert, but in an effort to help triage, looking at the code for MICEData here is what I can tell where those strange values are coming from. If I am reading the doc string for
_initial_imputationit may be working not as intended.Looking at

_initial_imputationinsideMICEDatathe docstring:The way I interpret that statement is that the missing values in a given column will initially be set to the observed value in the column closest to the mean. But in reality it is setting it to the absolute distance from the mean, which in the sample case is 0.5 for x1.
Where as the actual values that are closest should be something as follows:
Not sure if MICEData was intended to be used in that manner of just taking the initial imputation, or if was intended to be run through multiple iterations as that would bring the values in range. Running just one MICE iteration would provide values in the range of the observed data.
Again not an imputation expert so I cannot say how much effect it the initial value will have on one imputation iteration if it is indeed incorrect. My guess would be the effect depends on the actual numbers in the applicable dataset.
josef-pkt commentedon Oct 4, 2018
looks like a bug to me,
the effect could last for many iterations if the neighborhood is not densely populated.
swab2000 commentedon Oct 9, 2018
I appreciate your answer @jtweeder ,and it seems you are right. After several iterations by update_all(), MICEData gives me the right imputations. Thanks!