Generates Multivariate Imputations by Chained Equations (MICE)
1 2 3 4 5 6
ds.mice(vars = NULL, m = 5, type = "split", method = NULL, predictorMatrix = NULL, where = NULL, blocks = NULL, visitSequence = NULL, formulas = NULL, blots = NULL, post = NULL, defaultMethod = c("pmm", "logreg", "polyreg", "polr"), maxit = 5, printFlag = TRUE, seed = NA, data.init = NULL, datasources = NULL, ...)
Number of multiple imputations. The default is
Can be either a single string, or a vector of strings with
A numeric matrix of
A data frame or matrix with logicals of the same dimensions
List of vectors with variable names per block. List elements
may be named to identify blocks. Variables within a block are
imputed by a multivariate imputation method
A vector of block names of arbitrary length, specifying the
sequence of blocks that are imputed during one iteration of the Gibbs
sampler. A block is a collection of variables. All variables that are
members of the same block are imputed
when the block is visited. A variable that is a member of multiple blocks
is re-imputed within the same iteration.
A named list of formula's, or expressions that
can be converted into formula's by
A vector of strings with length
A vector of length 4 containing the default
imputation methods for 1) numeric data, 2) factor data with 2 levels, 3)
factor data with > 2 unordered levels, and 4) factor data with > 2
ordered levels. By default, the method uses
A scalar giving the number of iterations. The default is 5.
An integer that is used as argument by the
A data frame of the same size and type as
Named arguments that are passed down to the univariate imputation functions.
A data frame or a matrix containing the incomplete data. Missing
values are coded as
Generates multiple imputations for incomplete multivariate data by Gibbs sampling. Missing data can occur anywhere in the data. The algorithm imputes an incomplete column (the target column) by generating 'plausible' synthetic values given other columns in the data. Each incomplete column must act as a target column, and has its own specific set of predictors. The default set of predictors for a given target consists of all other columns in the data. For predictors that are incomplete themselves, the most recently generated imputations are used to complete the predictors prior to imputation of the target column.
A separate univariate imputation model can be specified for each column. The default imputation method depends on the measurement level of the target column. In addition to these, several other methods are provided. You can also write their own imputation functions, and call these from within the algorithm.
The data may contain categorical variables that are used in a regressions on other variables. The algorithm creates dummy variables for the categories of these variables, and imputes these from the corresponding categorical variable.
Built-in univariate imputation methods are:
||any||Predictive mean matching|
||any||Weighted predictive mean matching|
||any||Random sample from observed values|
||any||Classification and regression trees|
||any||Random forest imputations|
||numeric||Unconditional mean imputation|
||numeric||Bayesian linear regression|
||numeric||Linear regression ignoring model error|
||numeric||Linear regression using bootstrap|
||numeric||Linear regression, predicted values|
||numeric||Imputation of quadratic terms|
||numeric||Random indicator for nonignorable data|
||binary||Logistic regression with bootstrap|
||ordered||Proportional odds model|
||unordered||Polytomous logistic regression|
||unordered||Linear discriminant analysis|
||numeric||Level-1 normal heteroscedastic|
||numeric||Level-1 normal homoscedastic, lmer|
||numeric||Level-1 normal homoscedastic, pan|
||binary||Level-1 logistic, glmer|
||numeric||Level-2 class mean|
||numeric||Level-2 class normal|
||any||Level-2 class predictive mean matching|
These corresponding functions are coded in the
mice library under
method is a string with the
name of the univariate imputation method name, for example
method argument specifies the methods to be used. For the
mice() calls the first occurrence of
paste('mice.impute.', method[j], sep = '') in the search path. The
mechanism allows uses to write customized imputation function,
mice.impute.myfunc. To call it for all columns specify
method='myfunc'. To call it only for, say, column 2 specify
mice() supports a special built-in method,
called passive imputation. This method can be used to ensure that a data
transform always depends on the most recently generated imputations. In some
cases, an imputation model may need transformed data in addition to the
original data (e.g. log, quadratic, recodes, interaction, sum scores, and so
Passive imputation maintains consistency among different transformations of
the same data. Passive imputation is invoked if
~ is specified as the
first character of the string that specifies the univariate method.
mice() interprets the entire string, including the
as the formula argument in a call to
data[!r[,j],]). This provides a simple mechanism for specifying deterministic
dependencies among the columns. For example, suppose that the missing entries
data$weight are imputed. The body
mass index (BMI) can be calculated within
mice by specifying the
'~I(weight/height^2)' as the univariate imputation method for
the target column
data$bmi. Note that the
~ mechanism works
only on those entries which have missing values in the target column. You
should make sure that the combined observed and imputed parts of the target
column make sense. An easy way to create consistency is by coding all entries
in the target as
NA, but for large data sets, this could be
inefficient. Note that you may also need to adapt the default
predictorMatrix to evade linear dependencies among the predictors that
could cause errors like
Error in solve.default() or
system is exactly singular. Though not strictly needed, it is often useful
visitSequence such that the column that is imputed by the
~ mechanism is visited each time after one of its predictors was
visited. In that way, deterministic relation between columns will always be
#'A new argument
ls.meth can be parsed to the lower level
.norm.draw to specify the method for generating the least squares
estimates and any subsequently derived estimates. Argument
takes one of three inputs:
"qr" for QR-decomposition,
singular value decomposition and
"ridge" for ridge regression.
ls.meth defaults to
ls.meth = "qr".
Auxiliary predictors in formulas specification:
For a given block, the
formulas specification takes precedence over
the corresponding row in the
predictMatrix argument. This
precedence is, however, restricted to the subset of variables
specified in the terms of the block formula. Any
variables not specified by
formulas are imputed
according to the
predictMatrix specification. Variables with
type values in the
be added as main effects to the
formulas, which will
act as supplementary covariates in the imputation model. It is possible
to turn off this behavior by specifying the
auxiliary = FALSE.
Returns an S3 object of class
(multiply imputed data set)
Stef van Buuren firstname.lastname@example.org, Karin Groothuis-Oudshoorn email@example.com, 2000-2010, with contributions of Alexander Robitzsch, Gerko Vink, Shahab Jolani, Roel de Jong, Jason Turner, Lisa Doove, John Fox, Frank E. Harrell, and Peter Malewski.
Van Buuren, S., Groothuis-Oudshoorn, K. (2011).
Multivariate Imputation by Chained Equations in
R. Journal of
Statistical Software, 45(3), 1-67.
Van Buuren, S. (2018). Flexible Imputation of Missing Data. Second Edition. Chapman & Hall/CRC. Boca Raton, FL.
Van Buuren, S., Brand, J.P.L., Groothuis-Oudshoorn C.G.M., Rubin, D.B. (2006) Fully conditional specification in multivariate imputation. Journal of Statistical Computation and Simulation, 76, 12, 1049–1064.
Van Buuren, S. (2007) Multiple imputation of discrete and continuous data by fully conditional specification. Statistical Methods in Medical Research, 16, 3, 219–242.
Van Buuren, S., Boshuizen, H.C., Knook, D.L. (1999) Multiple imputation of missing blood pressure covariates in survival analysis. Statistics in Medicine, 18, 681–694.
Brand, J.P.L. (1999) Development, implementation and evaluation of multiple imputation strategies for the statistical analysis of incomplete data sets. Dissertation. Rotterdam: Erasmus University.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# do default multiple imputation on a numeric matrix imp <- mice(nhanes) imp # list the actual imputations for BMI imp$imp$bmi # first completed data matrix complete(imp) # imputation on mixed data with a different method per column mice(nhanes2, meth=c('sample','pmm','logreg','norm'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.