Exploratory Community

Filling NAs with MICE on Exploratory

#1

To fill NAs in numerical data with MICE algorithm, you can install mice package from CRAN, and call it as a Custom R Command Step.

  1. Install mice package from CRAN. Here is an instruction to install a custom R package.

  2. Keep only the numeric columns which you want to fill NAs with a Select step. You can create a Select step from a column header menu.

  1. Add a Custom R Command step to fill NAs with mice function with the following function expression. This expression is written in such a way that it takes a data frame as the first argument, and returns the resulting data frame, so that it works as a step in Exploratory.
(function(x){mice::complete(mice::mice(x))})()

  1. NAs are filled. Note that % of NAs are now all 0.

  1. To put back other columns, let’s create a branch from the step for the original data.

  1. On the branch, create a Select step, and this time remove the numeric columns we used for MICE, keeping only the other columns.

  1. Go back to the main branch, and bind the branch with the other columns that we just created.

  1. Now the original columns are put back with the NA-filled numeric columns!

1 Like