MadMan
MadMan

Reputation: 65

How to impute only one or some columns with mice R

I am experimenting with the mice package in R and am curious about how i can leave columns out of the imputation.

  1. If i want to run a mean imputation on just one column, the mice.impute.mean(y, ry, x = NULL, ...) function seems to be what I would use. I'm struggling to understand what i need to include as the third argument to get this to work.
  2. If i have a data set that includes categorical data such as name, ID, birth date, etc. which should not affect the calculation of other columns and should not be filled in when missing, how do i tell mice to exclude these columns in its calculation?

I've been using the mice dataset nhanes for my exploration.

Thanks

Upvotes: 3

Views: 3863

Answers (1)

Steffen Moritz
Steffen Moritz

Reputation: 7730

I don't know your data thus I can't create a example for you, but you are looking exactly for this parameters of the mice() function

predictorMatrix
A numeric matrix of length(blocks) rows and ncol(data) columns, containing 0/1 data specifying the set of predictors to be used for each target column. Each row corresponds to a variable block, i.e., a set of variables to be imputed. A value of 1 means that the column variable is used as a predictor for the target block (in the rows). By default, the predictorMatrix is a square matrix of ncol(data) rows and columns with all 1's, except for the diagonal. Note: For two-level imputation models (which have "2l" in their names) other codes (e.g, 2 or -2) are also allowed.

With this parameter you can define, which columns you want to use to impute a specific column.

where
A data frame or matrix with logicals of the same dimensions as data indicating where in the data the imputations should be created. The default, where = is.na(data), specifies that the missing data should be imputed. The where argument may be used to overimpute observed data, or to skip imputations for selected missing values.

Here you can define, for which columns you want to create imputation.

Upvotes: 7

Related Questions