mice {mice} | R Documentation |
Produces an object of class "mids"
, which stands
for 'multiply imputed data set'. Multivariate missing data
are imputed under Fully Conditional Specification (FCS).
mice(data, m = 5, imputationMethod = vector("character",length=ncol(data)), predictorMatrix = (1 - diag(1, ncol(data))), visitSequence = (1:ncol(data))[apply(is.na(data),2,any)], defaultImputationMethod=c("pmm","logreg","polyreg"), maxit = 5, diagnostics = TRUE, printFlag = TRUE, seed = NA)
data |
A data frame or a matrix containing the incomplete data. Missing values are coded as NA . |
m |
Number of multiple imputations, $m$. The default is $m=5$. |
imputationMethod |
Can be either a single string,
or a vector of strings with length ncol(data) ,
specifying the elementary imputation method to be used
for each column in data. If specified as a single
string, the same method will be used for all columns.
The default imputation method (when no argument is specified)
depends on the measurement level of the target column and
are specified by the
defaultImputationMethod argument.
Columns that need not be imputed have method "" .
See details for more information. |
predictorMatrix |
A square matrix of size ncol(data) containing 0/1 data specifying
the set of predictors to be used for each target column. Rows correspond
to target variables (i.e. variables to be imputed), in the sequence as
they appear in data. A value of '1' means that the column variable is
used as a predictor for the target variable (in the rows). The diagonal
of predictorMatrix must be zero. The default for predictorMatrix is that
all other columns are used as predictors (sometimes called massive
imputation). |
visitSequence |
A vector of integers of arbitrary length, specifying the column indices
of the visiting sequence. The visiting sequence is the column order that
is used to impute the data during one pass through the data. A
column may be visited more than once. All incomplete columns that are
used as predictors should be visited, or else the function will stop
with an error. The default sequence 1:ncol(data) implies that columns
are imputed from left to right. |
defaultImputationMethod |
A vector of three strings containing the default imputation methods for numerical columns, factor
columns with 2 levels, and factor columns with more than two levels, respectively. If nothing is
specified, the following defaults will be used:
pmm , predictive mean matching (numeric data)
logreg , logistic regression imputation (binary data, factor with 2 levels)
polyreg , polytomous regression imputation categorical data (factor >= 2 levels)
|
maxit |
A scalar giving the number of iterations. The default is 5. |
diagnostics |
A Boolean flag. If TRUE , diagnostic
information will be appended to the value of the function. If
FALSE , only the imputed data are saved. The default is TRUE . |
printFlag |
|
seed |
An integer between 0 and 1000 that is used by the set.seed()
for offsetting the random number generator. Default is to leave the random number generator alone. |
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. The extended model containing the
dummy variables is called the padded model. Its structure is stored in
the list component pad
.
Built-in elementary imputation methods are:
norm
norm.improper
pmm
mean
logreg
logreg2
polyreg
lda
sample
These corresponding functions are coded in the mice
library under
names
paste("mice.impute.",method,sep="")
, where method
is a string with the name of the elementary imputation method name,
for example method="norm"
. For the j
'th column, the mice
function constructs the function
name
paste("mice.impute.",imputationMethod[j],sep="")
and calls the
function with this name that occurs on top of the search path.
The mechanism allows uses to write customized imputation function,
mice.impute.myfunc
. To call it for all columns specify
imputationMethod="myfunc"
.
To call it only for, say, column 2 specify
imputationMethod=c("norm","myfunc","logreg",...)
.
Passive imputation:
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 on).
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 elementary method.
mice
interprets the entire string, including the ~
character,
as the formula argument
in a call to model.frame(formula, data[!r[,j],])
. This provides a simple
mechanism for specifying determinstic dependencies among the
columns. For example, suppose that the missing entries in
variables data$height
and data$weight
are imputed. The
body mass index (BMI) can be calculated within mice
by
specifying the string "~I(weight/height^2)"
as the elementary
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 Error: system is exactly singular
.
Though not strictly needed, it is often
useful to specify 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 synchronized.
Side effects:
Some elementary imputation method require access to the nnet
or MASS
libraries of Venables & Ripley. Where needed, these libraries will be
attached.
Returns an object of class "mids"
(multiply imputed data set) with components
call |
The call that created the object |
data |
A copy of the incomplete data set |
m |
The number of imputations |
nmis |
An array of length ncol(data) containing the number of missing observations
per column |
imp |
A list of ncol(data) components with the generated multiple imputations.
Each part of the list is a nmis[j] by m matrix of imputed values for
variable data[,j] . The component equals NULL for columns without
missing data. |
imputationMethod |
A vector of strings of length ncol(data) specifying the elementary
imputation method per column |
predictorMatrix |
A square matrix of size ncol(data) containing 0/1 data specifying
the predictor set |
visitSequence |
The sequence in which columns are visited |
seed |
The seed value of the solution |
iteration |
Last Gibbs sampling iteration number |
lastSeedValue |
The most recent seed value |
chainMean |
A list of m components. Each component is a length(visitSequence)
by maxit matrix containing the mean of the generated multiple
imputations. The array can be used for monitoring convergence.
Note that observed data are not present in this mean. |
chainCov |
A list with similar structure of chainMean , containing the covariances
of the imputed values. |
pad |
A list containing various settings of the padded imputation model, i.e. the imputation model after creating dummy variables. Normally, this array is only useful for error checking. |
Stef van Buuren (stef.vanbuuren@tno.nl), Karin Groothuis-Oudshoorn (k.groothuis@rrd.nl) (2000-2008) with contributions of Roel de Jong, John Fox, Frank E. Harrell, Martijn Heijmans, Jaap Brand, Peter Malewski.
Van Buuren, S., Groothuis-Oudshoorn, C.G.M. (2000) Multivariate Imputation by Chained Equations: MICE V1.0 User's manual. Leiden: TNO Quality of Life. http://www.stefvanbuuren.nl/publications/MICE V1.0 Manual TNO00038 2000.pdf
Van Buuren, S. (2007) Multiple imputation of discrete and continuous data by fully conditional specification. Statistical Methods in Medical Research, 16, 3, 219–242. http://www.stefvanbuuren.nl/publications/MI by FCS - SMMR 2007.pdf
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. http://www.stefvanbuuren.nl/publications/FCS in multivariate imputation - JSCS 2006.pdf
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. http://www.stefvanbuuren.nl/publications/Multiple imputation - Stat Med 1999.pdf
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.
complete
, mids
, lm.mids
, set.seed
data(nhanes) # do default multiple imputation on a numeric matrix imp <- mice(nhanes) imp # list the actual imputations for BMI imp$imputations$bmi # first completed data matrix complete(imp) # repeated linear regression on imputed data lm.mids(chl~age+bmi+hyp, imp) # imputation on mixed data with a different method per column data(nhanes2) mice(nhanes2,im=c("sample","pmm","logreg","norm"))