Content uploaded by Catharina G Groothuis-Oudshoorn

Author content

All content in this area was uploaded by Catharina G Groothuis-Oudshoorn on Nov 20, 2014

Content may be subject to copyright.

Available via license: CC BY 4.0

Content may be subject to copyright.

JSS Journal of Statistical Software

December 2011, Volume 45, Issue 3. http://www.jstatsoft.org/

mice: Multivariate Imputation by Chained

Equations in R

Stef van Buuren

TNO

Karin Groothuis-Oudshoorn

University of Twente

Abstract

The Rpackage mice imputes incomplete multivariate data by chained equations. The

software mice 1.0 appeared in the year 2000 as an S-PLUS library, and in 2001 as an

Rpackage. mice 1.0 introduced predictor selection, passive imputation and automatic

pooling. This article documents mice 2.9, which extends the functionality of mice 1.0

in several ways. In mice 2.9, the analysis of imputed data is made completely general,

whereas the range of models under which pooling works is substantially extended. mice 2.9

adds new functionality for imputing multilevel data, automatic predictor selection, data

handling, post-processing imputed values, specialized pooling routines, model selection

tools, and diagnostic graphs. Imputation of categorical data is improved in order to bypass

problems caused by perfect prediction. Special attention is paid to transformations, sum

scores, indices and interactions using passive imputation, and to the proper setup of

the predictor matrix. mice 2.9 can be downloaded from the Comprehensive RArchive

Network. This article provides a hands-on, stepwise approach to solve applied incomplete

data problems.

Keywords: MICE, multiple imputation, chained equations, fully conditional speciﬁcation,

Gibbs sampler, predictor selection, passive imputation, R.

1. Introduction

Multiple imputation (Rubin 1987,1996) is the method of choice for complex incomplete data

problems. Missing data that occur in more than one variable presents a special challenge.

Two general approaches for imputing multivariate data have emerged: joint modeling (JM)

and fully conditional speciﬁcation (FCS), also known as multivariate imputation by chained

equations (MICE). Schafer (1997) developed various JM techniques for imputation under the

multivariate normal, the log-linear, and the general location model. JM involves specifying a

multivariate distribution for the missing data, and drawing imputation from their conditional

2mice: Multivariate Imputation by Chained Equations in R

distributions by Markov chain Monte Carlo (MCMC) techniques. This methodology is attrac-

tive if the multivariate distribution is a reasonable description of the data. FCS speciﬁes the

multivariate imputation model on a variable-by-variable basis by a set of conditional densities,

one for each incomplete variable. Starting from an initial imputation, FCS draws imputations

by iterating over the conditional densities. A low number of iterations (say 10–20) is often

suﬃcient. FCS is attractive as an alternative to JM in cases where no suitable multivariate

distribution can be found. The basic idea of FCS is already quite old, and has been proposed

using a variety of names: stochastic relaxation (Kennickell 1991), variable-by-variable im-

putation (Brand 1999), regression switching (van Buuren et al. 1999), sequential regressions

(Raghunathan et al. 2001), ordered pseudo-Gibbs sampler (Heckerman et al. 2001), partially

incompatible MCMC (Rubin 2003), iterated univariate imputation (Gelman 2004), MICE

(van Buuren and Oudshoorn 2000;van Buuren and Groothuis-Oudshoorn 2011) and FCS

(van Buuren 2007).

Software implementations

Several authors have implemented fully conditionally speciﬁed models for imputation. mice 1.0

(van Buuren and Oudshoorn 2000) was released as an S-PLUS library in 2000, and was con-

verted by several users into R(RDevelopment Core Team 2011). IVEware (Raghunathan

et al. 2001) is a SAS-based procedure that was independently developed by Raghunathan and

colleagues. The function aRegImpute in Rand S-PLUS is part of the Hmisc package (Harrell

2001). The ice software (Royston 2004,2005;Royston and White 2011) is a widely used

implementation in Stata.SOLAS 3.0 (Statistical Solutions 2001) is also based on conditional

speciﬁcation, but does not iterate. WinMICE (Jacobusse 2005) is a Windows stand-alone

program for generating imputations under the hierarchical linear model. A recent addition

is the Rpackage mi (Su et al. 2011). Furthermore, FCS is now widely available through

the multiple imputation procedure part of the SPSS 17 Missing Values Analysis add-on

module. See http://www.multiple-imputation.com/ for an overview.

Applications of chained equations

Applications of imputation by chained equations have now appeared in quite diverse ﬁelds:

addiction (Schnoll et al. 2006;MacLeod et al. 2008;Adamczyk and Palmer 2008;Caria et al.

2009;Morgenstern et al. 2009), arthritis and rheumatology (Wolfe et al. 2006;Rahman et al.

2008;van den Hout et al. 2009), atherosclerosis (Tiemeier et al. 2004;van Oijen et al. 2007;

McClelland et al. 2008), cardiovascular system (Ambler et al. 2005;van Buuren et al. 2006a;

Chase et al. 2008;Byrne et al. 2009;Klein et al. 2009), cancer (Clark et al. 2001,2003;Clark

and Altman 2003;Royston et al. 2004;Barosi et al. 2007;Fernandes et al. 2008;Sharma et al.

2008;McCaul et al. 2008;Huo et al. 2008;Gerestein et al. 2009), epidemiology (Cummings

et al. 2006;Hindorﬀ et al. 2008;Mueller et al. 2008;Ton et al. 2009), endocrinology (Rouxel

et al. 2004;Prompers et al. 2008), infectious diseases (Cottrell et al. 2005;Walker et al.

2006;Cottrell et al. 2007;Kekitiinwa et al. 2008;Nash et al. 2008;Sabin et al. 2008;Thein

et al. 2008;Garabed et al. 2008;Michel et al. 2009), genetics (Souverein et al. 2006), health

economics (Briggs et al. 2003;Burton et al. 2007;Klein et al. 2008;Marshall et al. 2009),

obesity and physical activity (Orsini et al. 2008a;Wiles et al. 2008;Orsini et al. 2008b;van

Vlierberghe et al. 2009), pediatrics and child development (Hill et al. 2004;Mumtaz et al.

2007;Deave et al. 2008;Samant et al. 2008;Butler and Heron 2008;Ramchandani et al.

2008;van Wouwe et al. 2009), rehabilitation (van der Hulst et al. 2008), behavior (Veenstra

Journal of Statistical Software 3

et al. 2005;Melhem et al. 2007;Horwood et al. 2008;Rubin et al. 2008), quality of care (Sisk

et al. 2006;Roudsari et al. 2007;Ward and Franks 2007;Grote et al. 2007;Roudsari et al.

2008;Grote et al. 2008;Sommer et al. 2009), human reproduction (Smith et al. 2004a,b;

Hille et al. 2005;Alati et al. 2006;O’Callaghan et al. 2006;Hille et al. 2007;Hartog et al.

2008), management sciences (Jensen and Roy 2008), occupational health (Heymans et al.

2007;Brunner et al. 2007;Chamberlain et al. 2008), politics (Tanasoiu and Colonescu 2008),

psychology (Sundell et al. 2008) and sociology (Finke and Adamczyk 2008). All authors use

some form of chained equations to handle the missing data, but the details vary considerably.

The interested reader could check out articles from a familiar application area to see how

multiple imputation is done and reported.

Features

This paper describes the Rpackage mice 2.9 for multiple imputation: generating multiple

imputation, analyzing imputed data, and for pooling analysis results. Speciﬁc features of the

software are:

Columnwise speciﬁcation of the imputation model (Section 3.2).

Arbitrary patterns of missing data (Section 6.2).

Passive imputation (Section 3.4).

Subset selection of predictors (Section 3.3).

Support of arbitrary complete-data methods (Section 5.1).

Support pooling various types of statistics (Section 5.3).

Diagnostics of imputations (Section 4.5).

Callable user-written imputation functions (Section 6.1).

Package mice 2.9 replaces version mice 1.21, but is compatible with previous versions. This

document replaces the original manual (van Buuren and Oudshoorn 2000). The mice 2.9

package extends mice 1.0 in several ways. New features in mice 2.9 include:

quickpred() for automatic generation of the predictor matrix (Section 3.3).

mice.impute.2L.norm() for imputing multilevel data (Section 3.3).

Stable imputation of categorical data (Section 4.4).

Post-processing imputations through the post argument (Section 3.5).

with.mids() for general data analysis on imputed data (Section 5.1).

pool.scalar() and pool.r.squared() for specialized pooling (Section 5.3).

pool.compare() for model testing on imputed data (Section 5.3).

cbind.mids(),rbind.mids() and ibind() for combining imputed data (see help ﬁle

of these functions).

4mice: Multivariate Imputation by Chained Equations in R

Furthermore, this document introduces a new strategy to specify the predictor matrix in

conjunction with passive imputation. The amount and scope of example code has been

expanded considerably. All programming code used in this paper is available in the ﬁle

v45i03.R along with the manuscript and as doc/JSScode.R in the mice package.

The intended audience of this paper consists of applied researchers who want to address prob-

lems caused by missing data by multiple imputation. The text assumes basic familiarity with

R. The document contains hands-on analysis using the mice package. We do not discuss prob-

lems of incomplete data in general. We refer to the excellent books by Little and Rubin (2002)

and Schafer (1997). Theory and applications of multiple imputation have been developed in

Rubin (1987) and Rubin (1996). van Buuren (2012) introduces multiple imputation from an

applied perspective.

Package mice 2.9 was written in pure Rusing old-style S3 classes and methods. mice 2.9 was

written and tested in R2.12.2. The package has a simple architecture, is highly modular, and

allows easy access to all program code from within the Renvironment.

2. General framework

To the uninitiated, multiple imputation is a bewildering technique that diﬀers substantially

from conventional statistical approaches. As a result, the ﬁrst-time user may get lost in

a labyrinth of imputation models, missing data mechanisms, multiple versions of the data,

pooling, and so on. This section describes a modular approach to multiple imputation that

forms the basis of the architecture of mice. The philosophy behind the MICE methodology is

that multiple imputation is best done as a sequence of small steps, each of which may require

diagnostic checking. Our hope is that the framework will aid the user to map out the steps

needed in practical applications.

2.1. Notation

Let Yjwith (j= 1, . . . , p) be one of pincomplete variables, where Y= (Y1, . . . , Yp). The

observed and missing parts of Yjare denoted by Yobs

jand Ymis

j, respectively, so Yobs =

(Yobs

1, . . . , Y obs

p) and Ymis = (Ymis

1, . . . , Y mis

p) stand for the observed and missing data in Y.

The number of imputation is equal to m≥1. The hth imputed data sets is denoted as Y(h)

where h= 1, . . . , m. Let Y−j= (Y1, . . . , Yj−1, Yj+1, . . . , Yp) denote the collection of the p−1

variables in Yexcept Yj. Let Qdenote the quantity of scientiﬁc interest (e.g., a regression

coeﬃcient). In practice, Qis often a multivariate vector. More generally, Qencompasses any

model of scientiﬁc interest.

2.2. Modular approach to multiple imputation

Figure 1 illustrates the three main steps in multiple imputation: imputation, analysis and

pooling. The software stores the results of each step in a speciﬁc class: mids,mira and mipo.

We now explain each of these in more detail.

The leftmost side of the picture indicates that the analysis starts with an observed, incom-

plete data set Yobs. In general, the problem is that we cannot estimate Qfrom Yobs without

making unrealistic assumptions about the unobserved data. Multiple imputation is a general

framework that several imputed versions of the data by replacing the missing values by plau-

Journal of Statistical Software 5

incomplete data imputed data analysis results pooled results

data frame mids mira mipo

mice() with() pool()

Figure 1: Main steps used in multiple imputation.

sible data values. These plausible values are drawn from a distribution speciﬁcally modeled

for each missing entry. In mice this task is being done by the function mice(). Figure 1

portrays m= 3 imputed data sets Y(1), . . . , Y (3). The three imputed sets are identical for the

non-missing data entries, but diﬀer in the imputed values. The magnitude of these diﬀerence

reﬂects our uncertainty about what value to impute. The package has a special class for

storing the imputed data: a multiply imputed dataset of class mids.

The second step is to estimate Qon each imputed data set, typically by the method we

would have used if the data had been complete. This is easy since all data are now com-

plete. The model applied to Y(1), . . . , Y (m)is the generally identical. mice 2.9 contains a

function with.mids() that perform this analysis. This function supersedes the lm.mids()

and glm.mids(). The estimates ˆ

Q(1),..., ˆ

Q(m)will diﬀer from each other because their input

data diﬀer. It is important to realize that these diﬀerences are caused because of our uncer-

tainty about what value to impute. In mice the analysis results are collectively stored as a

multiply imputed repeated analysis within an Robject of class mira.

The last step is to pool the mestimates ˆ

Q(1),..., ˆ

Q(m)into one estimate ¯

Qand estimate its

variance. For quantities Qthat are approximately normally distributed, we can calculate the

mean over ˆ

Q(1),..., ˆ

Q(m)and sum the within- and between-imputation variance according

to the method outlined in Rubin (1987, pp. 76–77). The function pool() contains methods

for pooling quantities by Rubin’s rules. The results of the function is stored as a multiple

imputed pooled outcomes object of class mipo.

2.3. MICE algorithm

The imputation model should

Account for the process that created the missing data.

Preserve the relations in the data.

Preserve the uncertainty about these relations.

The hope is that adherence to these principles will yield imputations that are statistically

6mice: Multivariate Imputation by Chained Equations in R

correct as in Rubin (1987, Chapter 4) for a wide range in Q. Typical problems that may

surface while imputing multivariate missing data are

For a given Yj, predictors Y−jused in the imputation model may themselves be incom-

plete.

Circular dependence can occur, where Y1depends on Y2and Y2depends on Y1because

in general Y1and Y2are correlated, even given other variables.

Especially with large pand small n, collinearity and empty cells may occur.

Rows or columns can be ordered, e.g., as with longitudinal data.

Variables can be of diﬀerent types (e.g., binary, unordered, ordered, continuous), thereby

making the application of theoretically convenient models, such as the multivariate

normal, theoretically inappropriate.

The relation between Yjand Y−jcould be complex, e.g., nonlinear, or subject to cen-

soring processes.

Imputation can create impossible combinations (e.g., pregnant fathers), or destroy de-

terministic relations in the data (e.g., sum scores).

Imputations can be nonsensical (e.g., body temperature of the dead).

Models for Qthat will be applied to the imputed data may not (yet) be known.

This list is by no means exhaustive, and other complexities may appear for particular data.

In order to address the issues posed by the real-life complexities of the data, it is convenient

to specify the imputation model separately for each column in the data. This has led by to

the development of the technique of chained equations. Speciﬁcation occurs on at a level that

is well understood by the user, i.e., at the variable level. Moreover, techniques for creating

univariate imputations have been well developed.

Let the hypothetically complete data Ybe a partially observed random sample from the p-

variate multivariate distribution P(Y|θ). We assume that the multivariate distribution of Y

is completely speciﬁed by θ, a vector of unknown parameters. The problem is how to get the

multivariate distribution of θ, either explicitly or implicitly. The MICE algorithm obtains the

posterior distribution of θby sampling iteratively from conditional distributions of the form

P(Y1|Y−1, θ1)

.

.

.

P(Yp|Y−p, θp).

The parameters θ1, . . . , θpare speciﬁc to the respective conditional densities and are not

necessarily the product of a factorization of the ‘true’ joint distribution P(Y|θ). Starting from

a simple draw from observed marginal distributions, the tth iteration of chained equations is

a Gibbs sampler that successively draws

θ∗(t)

1∼P(θ1|Yobs

1, Y (t−1)

2, . . . , Y (t−1)

p)

Journal of Statistical Software 7

Y∗(t)

1∼P(Y1|Yobs

1, Y (t−1)

2, . . . , Y (t−1)

p, θ∗(t)

1)

.

.

.

θ∗(t)

p∼P(θp|Yobs

p, Y (t)

1, . . . , Y (t)

p−1)

Y∗(t)

p∼P(Yp|Yobs

p, Y (t)

1, . . . , Y (t)

p, θ∗(t)

p)

where Y(t)

j= (Yobs

j, Y ∗(t)

j) is the jth imputed variable at iteration t. Observe that previous

imputations Y∗(t−1)

jonly enter Y∗(t)

jthrough its relation with other variables, and not directly.

Convergence can therefore be quite fast, unlike many other MCMC methods. It is important

to monitor convergence, but in our experience the number of iterations can often be a small

number, say 10–20. The name chained equations refers to the fact that the MICE algorithm

can be easily implemented as a concatenation of univariate procedures to ﬁll out the missing

data. The mice() function executes mstreams in parallel, each of which generates one

imputed data set.

The MICE algorithm possesses a touch of magic. The method has been found to work well

in a variety of simulation studies (Brand 1999;Horton and Lipsitz 2001;Moons et al. 2006;

van Buuren et al. 2006b;Horton and Kleinman 2007;Yu et al. 2007;Schunk 2008;Drechsler

and Rassler 2008;Giorgi et al. 2008). Note that it is possible to specify models for which

no known joint distribution exits. Two linear regressions specify a joint multivariate normal

given speciﬁc regularity condition (Arnold and Press 1989). However, the joint distribution

of one linear and, say, one proportional odds regression model is unknown, yet very easy to

specify with the MICE framework. The conditionally speciﬁed model may be incompatible

in the sense that the joint distribution cannot exist. It is not yet clear what the consequences

of incompatibility are on the quality of the imputations. The little simulation work that is

available suggests that the problem is probably not serious in practice (van Buuren et al.

2006b;Drechsler and Rassler 2008). Compatible multivariate imputation models (Schafer

1997) have been found to work in a large variety of cases, but may lack ﬂexibility to ad-

dress speciﬁc features of the data. Gelman and Raghunathan (2001) remark that “separate

regressions often make more sense than joint models”. In order to bypass the limitations

of joint models, Gelman (2004, pp. 541) concludes: “Thus we are suggesting the use of a

new class of models—inconsistent conditional distributions—that were initially motivated by

computational and analytical convenience.” As a safeguard to evade potential problems by

incompatibility, we suggest that the order in which variable are imputed should be sensible.

This ordering can be speciﬁed in mice (cf. Section 3.6). Existence and uniqueness theorems

for conditionally speciﬁed models have been derived (Arnold and Press 1989;Arnold et al.

1999;Ip and Wang 2009). More work along these lines would be useful in order to identify

the boundaries at which the MICE algorithm breaks down. Barring this, the method seems

to work well in many examples, is of great importance in practice, and is easily applied.

2.4. Simple example

The section presents a simple example incorporating all three steps. After installing the

Rpackage mice from the Comprehensive RArchive Network (CRAN), load the package.

R> library("mice")

This paper uses the features of mice 2.9. The data frame nhanes contains data from Schafer

8mice: Multivariate Imputation by Chained Equations in R

(1997, p. 237). The data contains four variables: age (age group), bmi (body mass index),

hyp (hypertension status) and chl (cholesterol level). The data are stored as a data frame.

Missing values are represented as NA.

R> nhanes

age bmi hyp chl

1 1 NA NA NA

2 2 22.7 1 187

3 1 NA 1 187

4 3 NA NA NA

5 1 20.4 1 113

...

Inspecting the missing data

The number of the missing values can be counted and visualized as follows:

R> md.pattern(nhanes)

age hyp bmi chl

1311110

111011

311101

110012

710003

0 8 9 10 27

There are 13 (out of 25) rows that are complete. There is one row for which only bmi is

missing, and there are seven rows for which only age is known. The total number of missing

values is equal to (7 ×3) + (1 ×2) + (3 ×1) + (1 ×1) = 27. Most missing values (10) occur

in chl.

Another way to study the pattern involves calculating the number of observations per patterns

for all pairs of variables. A pair of variables can have exactly four missingness patterns: both

variables are observed (pattern rr), the ﬁrst variable is observed and the second variable is

missing (pattern rm), the ﬁrst variable is missing and the second variable is observed (pattern

mr), and both are missing (pattern mm). We can use the md.pairs() function to calculate the

frequency in each pattern for all variable pairs as

R> p <- md.pairs(nhanes)

R> p

$rr

age bmi hyp chl

age 25 16 17 15

bmi 16 16 16 13

Journal of Statistical Software 9

hyp 17 16 17 14

chl 15 13 14 15

$rm

age bmi hyp chl

age 0 9 8 10

bmi0003

hyp0103

chl0210

$mr

age bmi hyp chl

age0000

bmi9012

hyp8001

chl 10 3 3 0

$mm

age bmi hyp chl

age0000

bmi0987

hyp0887

chl 0 7 7 10

Thus, for pair (bmi,chl) there are 13 completely observed pairs, 3 pairs for which bmi is

observed but hyp not, 2 pairs for which bmi is missing but with hyp observed, and 7 pairs

with both missing bmi and hyp. Note that these numbers add up to the total sample size.

The Rpackage VIM (Templ et al. 2011) contains functions for plotting incomplete data. The

margin plot of the pair (bmi,chl) can be plotted by

R> library("VIM")

R> marginplot(nhanes[, c("chl", "bmi")], col = mdc(1:2), cex = 1.2,

+ cex.lab = 1.2, cex.numbers = 1.3, pch = 19)

Figure 2displays the result. The data area holds 13 blue points for which both bmi and chl

were observed. The plot in Figure 2requires a graphic device that supports transparent

colors, e.g., pdf(). To create the plot in other devices, change the col = mdc(1:2) argument

to col = mdc(1:2, trans = FALSE). The three red dots in the left margin correspond to

the records for which bmi is observed and chl is missing. The points are drawn at the known

values of bmi at 24.9, 25.5 and 29.6. Likewise, the bottom margin contain two red points with

observed chl and missing bmi. The red dot at the intersection of the bottom and left margin

indicates that there are records for which both bmi and chl are missing. The three numbers

at the lower left corner indicate the number of incomplete records for various combinations.

There are 9 records in which bmi is missing, 10 records in which chl is missing, and 7 records

in which both are missing. Furthermore, the left margin contain two box plots, a blue and

a red one. The blue box plot in the left margin summarizes the marginal distribution of bmi

of the 13 blue points. The red box plot summarizes the distribution of the three bmi values

10 mice: Multivariate Imputation by Chained Equations in R

● ● ●●

9

7

150 200 250

20 25 30 35

chl

bmi

Figure 2: Margin plot of bmi versus chl as drawn by the marginplot() function in the VIM

package. Observed data in blue, missing data in red.

with missing chl. Under MCAR, these distribution are expected to be identical. Likewise,

the two colored box plots in the bottom margin summarize the respective distributions for

chl.

Creating imputations

Creating imputations can be done with a call to mice() as follows:

R> imp <- mice(nhanes, seed = 23109)

iter imp variable

1 1 bmi hyp chl

1 2 bmi hyp chl

1 3 bmi hyp chl

1 4 bmi hyp chl

1 5 bmi hyp chl

2 1 bmi hyp chl

2 2 bmi hyp chl

...

where the multiply imputed data set is stored in the object imp of class mids. Inspect what

the result looks like

R> print(imp)

Journal of Statistical Software 11

Multiply imputed data set

Call:

mice(data = nhanes, seed = 23109)

Number of multiple imputations: 5

Missing cells per column:

age bmi hyp chl

0 9 8 10

Imputation methods:

age bmi hyp chl

"" "pmm" "pmm" "pmm"

VisitSequence:

bmi hyp chl

234

PredictorMatrix:

age bmi hyp chl

age0000

bmi1011

hyp1101

chl1110

Random generator seed value: 23109

Imputations are generated according to the default method, which is, for numerical data, pre-

dictive mean matching (pmm). The entries imp$VisitSequence and imp$PredictorMatrix

are algorithmic options that will be discusses later. The default number of multiple imputa-

tions is equal to m= 5.

Diagnostic checking

An important step in multiple imputation is to assess whether imputations are plausible.

Imputations should be values that could have been obtained had they not been missing.

Imputations should be close to the data. Data values that are clearly impossible (e.g., negative

counts, pregnant fathers) should not occur in the imputed data. Imputations should respect

relations between variables, and reﬂect the appropriate amount of uncertainty about their

‘true’ values. Diagnostic checks on the imputed data provide a way to check the plausibility

of the imputations. The imputations for bmi are stored as

R> imp$imp$bmi

12345

1 29.6 27.2 29.6 27.5 29.6

3 29.6 26.3 29.6 30.1 28.7

4 20.4 29.6 27.2 24.9 21.7

6 21.7 25.5 27.4 21.7 21.7

10 20.4 22.0 28.7 29.6 22.5

11 22.0 35.3 35.3 30.1 29.6

12 20.4 28.7 27.2 27.5 25.5

16 22.0 35.3 30.1 29.6 28.7

21 27.5 33.2 22.0 35.3 22.0

12 mice: Multivariate Imputation by Chained Equations in R

Each row corresponds to a missing entry in bmi. The columns contain the multiple impu-

tations. The completed data set combines the observed and imputed values. The (ﬁrst)

completed data set can be obtained as

R> complete(imp)

age bmi hyp chl

1 1 29.6 1 238

2 2 22.7 1 187

3 1 29.6 1 187

4 3 20.4 1 186

5 1 20.4 1 113

...

The complete() function extracts the ﬁve imputed data sets from the imp object as a long

(row-stacked) matrix with 125 records. The missing entries in nhanes have now been ﬁlled by

the values from the ﬁrst (of ﬁve) imputation. The second completed data set can be obtained

by complete(imp, 2). For the observed data, it is identical to the ﬁrst completed data set,

but it may diﬀer in the imputed data.

It is often useful to inspect the distributions of original and the imputed data. One way of

doing this is to use the function stripplot() in mice 2.9, an adapted version of the same

function in the package lattice (Sarkar 2008). The stripplot in Figure 3is created as

R> stripplot(imp, pch = 20, cex = 1.2)

The ﬁgure shows the distributions of the four variables as individual points. Blue points are

observed, the red points are imputed. The panel for age contains blue points only because

age is complete. Furthermore, note that the red points follow the blue points reasonably well,

including the gaps in the distribution, e.g., for chl.

The scatterplot of chl and bmi for each imputed data set in Figure 4is created by

R> xyplot(imp, bmi ~ chl | .imp, pch = 20, cex = 1.4)

The ﬁgure redraws ﬁgure 2, but now for the observed and imputed data. Imputations are

plotted in red. The blue points are the same across diﬀerent panels, but the red point vary.

The red points have more or less the same shape as blue data, which indicates that they could

have been plausible measurements if they had not been missing. The diﬀerences between the

red points represents our uncertainty about the true (but unknown) values.

Under MCAR, univariate distributions of the observed and imputed data are expected to

be identical. Under MAR, they can be diﬀerent, both in location and spread, but their

multivariate distribution is assumed to be identical. There are many other ways to look at

the completed data, but we defer of a discussion of those to Section 4.5.

Analysis of imputed data

Suppose that the complete-data analysis of interest is a linear regression of chl on age and

bmi. For this purpose, we can use the function with.mids(), a wrapper function that applies

the complete data model to each of the imputed data sets:

Journal of Statistical Software 13

Imputation number

1.0 1.5 2.0 2.5 3.0

0 1 2 3 4 5

age

20 25 30 35

0 1 2 3 4 5

bmi

1.0 1.2 1.4 1.6 1.8 2.0

0 1 2 3 4 5

hyp

150 200 250

0 1 2 3 4 5

chl

Figure 3: Stripplot of four variables in the original data and in the ﬁve imputed data sets.

Points are slightly jittered. Observed data in blue, imputed data in red.

R> fit <- with(imp, lm(chl ~ age + bmi))

The fit object has class mira and contains the results of ﬁve complete-data analyses. These

can be pooled as follows:

R> print(pool(fit))

Call: pool(object = fit)

Pooled coefficients:

(Intercept) age bmi

-34.158914 34.330666 6.212025

Fraction of information about the coefficients missing due to nonresponse:

(Intercept) age bmi

0.5747265 0.7501284 0.4795427

More detailed output can be obtained, as usual, with the summary() function, i.e.,

R> round(summary(pool(fit)), 2)

14 mice: Multivariate Imputation by Chained Equations in R

chl

bmi

20

25

30

35

0

150 200 250

1

2

150 200 250

3

4

150 200 250

20

25

30

35

5

Figure 4: Scatterplot of cholesterol (chl) and body mass index (bmi) in the original data

(panel 0), and ﬁve imputed data sets. Observed data in blue, imputed data in red.

est se t df Pr(>|t|) lo 95 hi 95 nmis fmi

(Intercept) -34.16 76.07 -0.45 6.81 0.67 -215.05 146.73 NA 0.57

age 34.33 14.86 2.31 4.04 0.08 -6.76 75.42 0 0.75

bmi 6.21 2.21 2.81 8.80 0.02 1.20 11.23 9 0.48

lambda

(Intercept) 0.47

age 0.65

bmi 0.37

After multiple imputation, we ﬁnd a signiﬁcant eﬀect bmi. The column fmi contains the

fraction of missing information as deﬁned in Rubin (1987), and the column lambda is the

proportion of the total variance that is attributable to the missing data (λ= (B+B/m)/T ).

The pooled results are subject to simulation error and therefore depend on the seed argument

of the mice() function. In order to minimize simulation error, we can use a higher number

of imputations, for example m=50. It is easy to do this as

R> imp50 <- mice(nhanes, m = 50, seed = 23109)

R> fit <- with(imp50, lm(chl ~ age + bmi))

R> round(summary(pool(fit)), 2)

est se t df Pr(>|t|) lo 95 hi 95 nmis

(Intercept) -35.53 63.61 -0.56 14.46 0.58 -171.55 100.49 NA

age 35.90 10.48 3.42 12.76 0.00 13.21 58.58 0

bmi 6.15 1.97 3.13 15.13 0.01 1.96 10.35 9

Journal of Statistical Software 15

fmi lambda

(Intercept) 0.35 0.27

age 0.43 0.35

bmi 0.32 0.24

We ﬁnd that actually both age and chl are signiﬁcant eﬀects. This is the result that can be

reported.

3. Imputation models

3.1. Seven choices

The speciﬁcation of the imputation model is the most challenging step in multiple imputation.

What are the choices that we need to make, and in what order? There are seven main choices:

1. First, we should decide whether the missing at random (MAR) assumption (Rubin 1976)

is plausible. The MAR assumption is a suitable starting point in many practical cases,

but there are also cases where the assumption is suspect. Schafer (1997, pp. 20–23)

provides a good set of practical examples. MICE can handle both MAR and missing not

at random (MNAR). Multiple imputation under MNAR requires additional modeling

assumptions that inﬂuence the generated imputations. There are many ways to do this.

We refer to Section 6.2 for an example of how that could be realized.

2. The second choice refers to the form of the imputation model. The form encompasses

both the structural part and the assumed error distribution. Within MICE the form

needs to be speciﬁed for each incomplete column in the data. The choice will be steered

by the scale of the dependent variable (i.e., the variable to be imputed), and preferably

incorporates knowledge about the relation between the variables. Section 3.2 describes

the possibilities within mice 2.9.

3. Our third choice concerns the set of variables to include as predictors into the imputation

model. The general advice is to include as many relevant variables as possible including

their interactions (Collins et al. 2001). This may however lead to unwieldy model

speciﬁcations that could easily get out of hand. Section 3.3 describes the facilities

within mice 2.9 for selecting the predictor set.

4. The fourth choice is whether we should impute variables that are functions of other

(incomplete) variables. Many data sets contain transformed variables, sum scores, in-

teraction variables, ratio’s, and so on. It can be useful to incorporate the transformed

variables into the multiple imputation algorithm. Section 3.4 describes how mice 2.9

deals with this situation using passive imputation.

5. The ﬁfth choice concerns the order in which variables should be imputed. Several

strategies are possible, each with their respective pro’s and cons. Section 3.6 shows how

the visitation scheme of the MICE algorithm within mice 2.9 is under control of the

user.

16 mice: Multivariate Imputation by Chained Equations in R

Method Description Scale type Default

pmm Predictive mean matching numeric Y

norm Bayesian linear regression numeric

norm.nob Linear regression, non-Bayesian numeric

mean Unconditional mean imputation numeric

2L.norm Two-level linear model numeric

logreg Logistic regression factor, 2 levels Y

polyreg Multinomial logit model factor, >2 levels Y

polr Ordered logit model ordered, >2 levels Y

lda Linear discriminant analysis factor

sample Random sample from the observed data any

Table 1: Built-in univariate imputation techniques. The techniques are coded as functions

named mice.impute.pmm(), and so on.

6. The sixth choice concerns the setup of the starting imputations and the number of

iterations. The convergence of the MICE algorithm can be monitored in many ways.

Section 4.3 outlines some techniques in mice 2.9 that assist in this task.

7. The seventh choice is m, the number of multiply imputed data sets. Setting mtoo low

may result in large simulation error, especially if the fraction of missing information is

high.

Please realize that these choices are always needed. The analysis in Section 2.4 imputed the

nhanes data using just a minimum of speciﬁcations and relied on mice defaults. However,

these default choices are not necessarily the best for your data. There is no magical setting

that produces appropriate imputations in every problem. Real problems need tailoring. It is

our hope that the software will invite you to go beyond the default settings.

3.2. Univariate imputation methods

In MICE one speciﬁes a univariate imputation model of each incomplete variable. Both

the structural part of the imputation model and the error distribution need to be speciﬁed.

The choice will depend on, amongst others, the scale of the variable to be imputed. The

univariate imputation method takes a set of (at that moment) complete predictors, and returns

a single imputation for each missing entry in the incomplete target column. The mice 2.9

package supplies a number of built-in univariate imputation models. These all have names

mice.impute.name, where name identiﬁes the univariate imputation method.

Table 1contains the list of built-in imputation functions. The default methods are indicated.

The method argument of mice() speciﬁes the imputation method per column and overrides

the default. If method is speciﬁed as one string, then all visited data columns (cf. Section 3.6)

will be imputed by the univariate function indicated by this string. So

R> imp <- mice(nhanes, method = "norm")

speciﬁes that the function mice.impute.norm() is called for all columns. Alternatively,

method can be a vector of strings of length ncol(data) specifying the function that is applied

to each column. Columns that need not be imputed have method "". For example,

Journal of Statistical Software 17

R> imp <- mice(nhanes, meth = c("", "norm", "pmm", "mean"))

applies diﬀerent methods for diﬀerent columns. The nhanes2 data frame contains one poly-

tomous, one binary and two numeric variables.

R> str(nhanes2)

'

data.frame

'

: 25 obs. of 4 variables:

$ age: Factor w/ 3 levels "20-39","40-59",..: 1 2 1 3 1 3 1 1 2 2 ...

$ bmi: num NA 22.7 NA NA 20.4 NA 22.5 30.1 22 NA ...

$ hyp: Factor w/ 2 levels "no","yes": NA 1 1 NA 1 NA 1 1 1 NA ...

$ chl: num NA 187 187 NA 113 184 118 187 238 NA ...

Imputations can be created as

R> imp <- mice(nhanes2, me = c("polyreg", "pmm", "logreg", "norm"))

where function mice.impute.polyreg() is used to impute the ﬁrst (categorical) variable age,

mice.impute.ppm() for the second numeric variable bmi, function mice.impute.logreg()

for the third binary variable hyp and function mice.impute.norm() for the numeric variable

chl. The me parameter is a legal abbreviation of the method argument.

Empty imputation method

The mice() function will automatically skip imputation of variables that are complete. One

of the problems in previous versions this function was that all incomplete data needed to

be imputed. In mice 2.9 it is possible to skip imputation of selected incomplete variables by

specifying the empty method "". This works as long as the incomplete variable that is skipped

is not being used as a predictor for imputing other variables. The mice() function will detect

this case, and automatically remove the variable from the predictor list. For example, suppose

that we do not want to impute bmi, but still want to retain in it the imputed data. We can

run the following

R> imp <- mice(nhanes2, meth = c("", "", "logreg", "norm"))

This statement runs because bmi is removed from the predictor list. When removal is not

possible, the program aborts with an error message like

Error in check.predictorMatrix(predictorMatrix, method, varnames,

nmis, : Variable bmi is used, has missing values, but is not imputed

Section 3.3 explains how to solve this problem.

Perfect prediction

Previous versions produced warnings like fitted probabilities numerically 0 or 1

occurred and algorithm did not converge on these data. These warnings are caused by

the sample size of 25 relative to the number of parameters. mice 2.9 implements more stable

18 mice: Multivariate Imputation by Chained Equations in R

algorithms into mice.impute.logreg() and mice.impute.polyreg() based on augmenting

the rows prior to imputation (White et al. 2010).

Default imputation method

The mice package distinguishes between four types of variables: numeric, binary (factor with

2 levels), and unordered (factor with more than 2 levels) and ordered (ordered factor with

more than 2 levels). Each type has a default imputation method, which are indicated in

Table 1. These defaults can be changed by the defaultMethod argument to the mice()

function. For example

R> mice(nhanes2, defaultMethod = c("norm", "logreg", "polyreg", "polr"))

applies the function mice.impute.norm() to each numeric variable in nhanes instead of

mice.impute.pmm(). It leaves the defaults for binary and categorical data unchanged. The

mice() function checks the type of the variable against the speciﬁed imputation method, and

produces a warning if a type mismatch is found.

Overview of imputation methods

The function mice.impute.pmm() implements predictive mean matching (Little 1988), a gen-

eral purpose semi-parametric imputation method. Its main virtues are that imputations are

restricted to the observed values and that it can preserve non-linear relations even if the

structural part of the imputation model is wrong. It is a good overall imputation method.

The functions mice.impute.norm() and mice.impute.norm.nob() impute according to a

linear imputation model, and are fast and eﬃcient if the model residuals are close to normal.

The second model ignores any sampling uncertainty of the imputation model, so it is only

appropriate for very large samples. The method mice.impute.mean() simply imputes the

mean of the observed data. Mean imputation is known to be a bad strategy, and the user

should be aware of the implications.

The function mice.impute.2L.norm() imputes according to the heteroscedastic linear two-

level model by a Gibbs sampler (Note: Interpret ‘2L’ as ‘two levels’, not as ‘twenty-one’). It

is new in mice 2.9. The method considerably improves upon standard methods that ignore

the clustering structure, or that model the clustering as ﬁxed eﬀects (van Buuren 2010). See

multilevel imputation in Section 3.3 for an example.

The function mice.impute.polyreg() imputes factor with two or more levels by the multi-

nomial model using the multinom() function in nnet (Venables and Ripley 2002) for the hard

work. The function mice.impute.polr() implements the ordered logit model, also known

as the proportional odds model. It calls polr from MASS (Venables and Ripley 2002). The

function mice.impute.lda() uses the MASS function lda() for linear discriminant analysis

to compute posterior probabilities for each incomplete case, and subsequently draws impu-

tations from these posteriors. This statistical properties of this method are not as good as

mice.impute.polyreg()(Brand 1999), but it is a bit faster and uses fewer resources. The

maximum number of categories these function handle is set to 50. Finally, the function

mice.impute.sample() just takes a random draw from the observed data, and imputes these

into missing cells. This function does not condition on any other variable. mice() calls

mice.impute.sample() for initialization.

Journal of Statistical Software 19

The univariate imputation functions are designed to be called from the main function mice(),

and this is by far the easiest way to invoke them. It is however possible to call them directly,

assuming that the arguments are all properly speciﬁed. See the documentation for more

details.

3.3. Predictor selection

One of the most useful features of the MICE algorithm is the ability to specify the set of

predictors to be used for each incomplete variable. The basic speciﬁcation is made through

the predictorMatrix argument, which is a square matrix of size ncol(data) containing 0/1

data. Each row in predictorMatrix identiﬁes which predictors are to be used for the variable

in the row name. If diagnostics = TRUE (the default), then mice() returns a mids object

containing a predictorMatrix entry. For example, type

R> imp <- mice(nhanes, print = FALSE)

R> imp$predictorMatrix

age bmi hyp chl

age0000

bmi1011

hyp1101

chl1110

The row correspond to incomplete target variables, in the sequence as they appear in data.

Row and column names of the predictorMatrix are ignored on input, and overwritten by

mice() on output. A value of 1indicates that the column variable is used as a predictor

to impute the target (row) variable, and a 0means that it is not used. Thus, in the above

example, bmi is predicted from age,hyp and chl. Note that the diagonal is 0since a variable

cannot predict itself. Since age contains no missing data, mice() silently sets all values in

the row to 0. The default setting of the predictorMatrix speciﬁes that all variables predict

all others.

Removing a predictor

The user can specify a custom predictorMatrix, thereby eﬀectively regulating the number of

predictors per variable. For example, suppose that bmi is considered irrelevant as a predictor.

Setting all entries within the bmi column to zero eﬀectively removes it from the predictor set,

e.g.,

R> pred <- imp$predictorMatrix

R> pred[, "bmi"] <- 0

R> pred

age bmi hyp chl

age0000

bmi1011

hyp1001

chl1010

20 mice: Multivariate Imputation by Chained Equations in R

will not use bmi as a predictor, but still impute it. Using this new speciﬁcation, we create

imputations as

R> imp <- mice(nhanes, pred = pred, pri = FALSE)

This imputes the incomplete variables hyp and chl without using bmi as a predictor.

Skipping imputation

Suppose that we want to skip imputation of bmi, and leave it as it is. This can be achieved

by 1) eliminating bmi from the predictor set, and 2) setting the imputation method to "".

More speciﬁcally

R> ini <- mice(nhanes2, maxit = 0, pri = FALSE)

R> pred <- ini$pred

R> pred[, "bmi"] <- 0

R> meth <- ini$meth

R> meth["bmi"] <- ""

R> imp <- mice(nhanes2, meth = meth, pred = pred, pri = FALSE)

R> imp$imp$bmi

12345

1 NA NA NA NA NA

3 NA NA NA NA NA

4 NA NA NA NA NA

6 NA NA NA NA NA

10 NA NA NA NA NA

11 NA NA NA NA NA

12 NA NA NA NA NA

16 NA NA NA NA NA

21 NA NA NA NA NA

The ﬁrst statement calls mice() with the maximum number of iterations maxit set to zero.

This is a fast way to create the mids object called ini containing the default settings. It

is then easy to copy and edit the predictorMatrix and method arguments of the mice()

function. Now mice() will impute NA into the missing values of bmi. In eﬀect, the original

bmi (with the missing values included) is copied into the multiply imputed data set. This

technique is not only useful for ‘keeping all the data together’, but also opens up ways to

performs imputation by nested blocks of variables. For examples where this could be useful,

see Shen (2000) and Rubin (2003).

Intercept imputation

Eliminating all predictors for bmi can be done by

R> pred <- ini$pred

R> pred["bmi", ] <- 0

R> imp <- mice(nhanes2, pred = pred, pri = FALSE, seed = 51162)

R> imp$imp$bmi

Journal of Statistical Software 21

12345

1 20.4 27.2 22.0 25.5 27.4

3 27.4 22.5 24.9 22.7 33.2

4 20.4 20.4 24.9 27.2 27.5

6 22.5 27.5 26.3 20.4 24.9

10 27.2 20.4 27.2 26.3 22.7

11 22.7 22.5 22.7 29.6 25.5

12 29.6 28.7 22.5 33.2 27.4

16 27.4 22.5 35.3 22.7 20.4

21 30.1 27.4 24.9 20.4 27.2

Imputations for bmi are now sampled (by mice.impute.pmm()) under the intercept-only

model. Note that these imputations are appropriate only under the MCAR assumption.

Multilevel imputation

Imputation of multilevel data poses special problems. Most techniques have been developed

under the joint modeling perspective (Schafer and Yucel 2002;Yucel 2008;Goldstein et al.

2009). Some work within the context of FCS has been done (Jacobusse 2005), but this is still

an open research area. The mice 2.9 package include the mice.impute.2L.norm() function,

which can be used to impute missing data under a linear multilevel model. The function

was contributed by Roel de Jong, and implements the Gibbs sampler for the linear multilevel

model where the within-class error variance is allowed to vary (Kasim and Raudenbush 1998).

Heterogeneity in the variances is essential for getting good imputations in multilevel data.

The method is an improvement over simpler methods like ﬂat-ﬁle imputation or per-group

imputation (van Buuren 2010).

Using mice.impute.2L.norm() (or equivalently mice.impute.2l.norm()) deviates from other

univariate imputation functions in mice 2.9 in two respects. It requires the speciﬁcation of

the ﬁxed eﬀects, the random eﬀects and the class variable. Furthermore, it assumes that the

predictors contain a column of ones representing the intercept. Random eﬀects are coded

in the predictor matrix as a ‘2’. The class variable (only one is allowed) is coded by a ‘-2’.

The example below uses the popularity data of (Hox 2002). The dependent variable is pupil

popularity, which contains 848 missing values. There are two random eﬀects: const (in-

tercept) and sex (slope), one ﬁxed eﬀect, teacher experience (texp), and one class variable

(school). Imputations can be generated as

R> popmis[1:3, ]

pupil school popular sex texp const teachpop

1 1 1 NA 1 24 1 7

2 2 1 NA 0 24 1 7

3 3 1 7 1 24 1 6

R> ini <- mice(popmis, maxit = 0)

R> pred <- ini$pred

R> pred["popular", ] <- c(0, -2, 0, 2, 1, 2, 0)

R> imp <- mice(popmis, meth = c("", "", "2l.norm", "", "",

+ "", ""), pred = pred, maxit = 1, seed = 71152)

22 mice: Multivariate Imputation by Chained Equations in R

iter imp variable

1 1 popular

1 2 popular

1 3 popular

1 4 popular

1 5 popular

The extension to the multivariate case will be obvious, but relatively little is known about

the statistical properties.

Advice on predictor selection

The predictorMatrix argument is especially useful when dealing with data sets with a large

number of variables. We now provide some advice regarding the selection of predictors for

large data, especially with many incomplete data.

As a general rule, using every bit of available information yields multiple imputations that

have minimal bias and maximal certainty (Meng 1995;Collins et al. 2001). This principle

implies that the number of predictors should be chosen as large as possible. Including as many

predictors as possible tends to make the MAR assumption more plausible, thus reducing the

need to make special adjustments for NMAR mechanisms (Schafer 1997).

However, data sets often contain several hundreds of variables, all of which can potentially

be used to generate imputations. It is not feasible (because of multicollinearity and computa-

tional problems) to include all these variables. It is also not necessary. In our experience, the

increase in explained variance in linear regression is typically negligible after the best, say,

15 variables have been included. For imputation purposes, it is expedient to select a suitable

subset of data that contains no more than 15 to 25 variables. van Buuren et al. (1999) provide

the following strategy for selecting predictor variables from a large data base:

1. Include all variables that appear in the complete-data model, i.e., the model that will

be applied to the data after imputation. Failure to do so may bias the complete-

data analysis, especially if the complete-data model contains strong predictive relations.

Note that this step is somewhat counter-intuitive, as it may seem that imputation

would artiﬁcially strengthen the relations of the complete-data model, which is clearly

undesirable. If done properly however, this is not the case. On the contrary, not

including the complete-data model variables will tend to bias the results towards zero.

Note that interactions of scientiﬁc interest also need to be included into the imputation

model.

2. In addition, include the variables that are related to the nonresponse. Factors that

are known to have inﬂuenced the occurrence of missing data (stratiﬁcation, reasons for

nonresponse) are to be included on substantive grounds. Others variables of interest are

those for which the distributions diﬀer between the response and nonresponse groups.

These can be found by inspecting their correlations with the response indicator of the

variable to be imputed. If the magnitude of this correlation exceeds a certain level, then

the variable is included.

3. In addition, include variables that explain a considerable amount of variance. Such

Journal of Statistical Software 23

predictors help to reduce the uncertainty of the imputations. They are crudely identiﬁed

by their correlation with the target variable.

4. Remove from the variables selected in steps 2 and 3 those variables that have too

many missing values within the subgroup of incomplete cases. A simple indicator is the

percentage of observed cases within this subgroup, the percentage of usable cases.

Most predictors used for imputation are incomplete themselves. In principle, one could apply

the above modeling steps for each incomplete predictor in turn, but this may lead to a cascade

of auxiliary imputation problems. In doing so, one runs the risk that every variable needs to be

included after all. In practice, there is often a small set of key variables, for which imputations

are needed, which suggests that steps 1 through 4 are to be performed for key variables only.

This was the approach taken in van Buuren et al. (1999), but it may miss important predictors

of predictors. A safer and more eﬃcient, though more laborious, strategy is to perform the

modeling steps also for the predictors of predictors of key variables. This is done in Oudshoorn

et al. (1999). We expect that it is rarely necessary to go beyond predictors of predictors. At

the terminal node, we can apply a simply method like mice.impute.sample() that does not

need any predictors for itself.

Quick predictor selection

Correlations for the strategy outlined above can be calculated with the standard function

cor(). For example,

R> round(cor(nhanes, use = "pair"), 3)

age bmi hyp chl

age 1.000 -0.372 0.506 0.507

bmi -0.372 1.000 0.051 0.373

hyp 0.506 0.051 1.000 0.429

chl 0.507 0.373 0.429 1.000

calculates Pearson correlations using all available cases in each pair of variables. Similarly,

R> round(cor(y = nhanes, x = !is.na(nhanes), use = "pair"),

+ 3)

age bmi hyp chl

age NA NA NA NA

bmi 0.086 NA 0.139 0.053

hyp 0.008 NA NA 0.045

chl -0.040 -0.012 -0.107 NA

calculates the mutual correlations between the data and the response indicators. The warning

can be safely ignored and is caused by the fact that age contains no missing data.

The proportion of usable cases measures how many cases with missing data on the target

variable actually have observed values on the predictor. The proportion will be low if both

24 mice: Multivariate Imputation by Chained Equations in R

target and predictor are missing on the same cases. If so, the predictor contains only little

information to impute the target variable, and could be dropped from the model, especially

if the bivariate relation is not primary scientiﬁc interest. The proportion of usable cases can

be calculated as

R> p <- md.pairs(nhanes)

R> round(p$mr/(p$mr + p$mm), 3)

age bmi hyp chl

age NaN NaN NaN NaN

bmi 1 0.0 0.111 0.222

hyp 1 0.0 0.000 0.125

chl 1 0.3 0.300 0.000

For imputing hyp only 1 out of 8 cases was observed in predictor chl. Thus, predictor chl

does not contain much information to impute hyp, despite the substantial correlation of 0.42.

If the relation is of no further scientiﬁc interest, omitting predictor chl from the model to

impute hyp will only have a small eﬀect. Note that proportion of usable cases is asymmetric.

mice 2.9 contains a new function quickpred() that calculates these quantities, and combines

them automatically in a predictorMatrix that can be used to call mice(). The quickpred()

function assumes that the correlation is a sensible measure for the data at hand (e.g., order

of factor levels should be reasonable). For example,

R> quickpred(nhanes)

age bmi hyp chl

age0000

bmi1011

hyp1001

chl1110

yields a predictorMatrix for a model that includes all predictors with an absolute correlation

with the target or with the response indicator of at least 0.1 (the default value of the mincor

argument). Observe that the predictor matrix need not always be symmetric. In particular,

bmi is not a predictor of hyp, but hyp is a predictor of bmi here. This can occur because the

correlation of hyp with the response indicator of bmi (0.139) exceeds the threshold.

The quickpred() function has arguments that change the minimum correlation, that allow

to select predictor based on their proportion of usable cases, and that can specify variables

that should always be included or excluded. It is also possible to specify thresholds per target

variable, or even per target-predictor combination. See the help ﬁles for more details.

It is easy to use the function in conjunction with mice(). For example,

R> imp <- mice(nhanes, pred = quickpred(nhanes, minpuc = 0.25,

+ include = "age"))

imputes the data from a model where the minimum proportion of usable cases is at least 0.25

and that always includes age as a predictor.

Journal of Statistical Software 25

Any interactions of interest need to be appended to the data before using quickpred(). For

large data, the user can experiment with the mincor,minpuc,include and exclude argu-

ments to trim the imputation problem to a reasonable size. The application of quickpred()

can substantially cut down the time needed to specify the imputation model for data with

many variables.

3.4. Passive imputation

There is often a need for transformed, combined or recoded versions of the data. In the

case of incomplete data, one could impute the original, and transform the completed original

afterwards, or transform the incomplete original and impute the transformed version. If,

however, both the original and the transform are needed within the imputation algorithm,

neither of these approaches work because one cannot be sure that the transformation holds

between the imputed values of the original and transformed versions.

mice implements a special mechanism, called passive imputation, to deal with such situ-

ations. Passive imputation maintains the consistency among diﬀerent transformations of

the same data. The method can be used to ensure that the transform always depends

on the most recently generated imputations in the original untransformed data. Passive

imputation is invoked by specifying a ~(tilde) as the ﬁrst character of the imputation

method. The entire string, including the ~is interpreted as the formula argument in a

call to model.frame(formula, data[!r[,j],]). This provides a simple method for spec-

ifying a large variety of dependencies among the variables, such as transformed variables,

recodes, interactions, sum scores, and so on, that may themselves be needed in other parts of

the algorithm.

Preserving a transformation

As an example, suppose that previous research suggested that bmi is better imputed from

log(chl) than from chl. We may thus want to add an extra column to the data with

log(chl), and impute bmi from log(chl). Any missing values in chl will also be present

in log(chl). The problem is to keep imputations in chl and log(chl) consistent with each

other, i.e., the imputations should respect their relationship. The following code will take

care of this:

R> nhanes2.ext <- cbind(nhanes2, lchl = log(nhanes2$chl))

R> ini <- mice(nhanes2.ext, max = 0, print = FALSE)

R> meth <- ini$meth

R> meth["lchl"] <- "~log(chl)"

R> pred <- ini$pred

R> pred[c("hyp", "chl"), "lchl"] <- 0

R> pred["bmi", "chl"] <- 0

R> pred

age bmi hyp chl lchl

age 0 0 0 0 0

bmi 1 0 1 0 1

hyp 1 1 0 1 0

26 mice: Multivariate Imputation by Chained Equations in R

chl 1 1 1 0 0

lchl 1 1 1 1 0

R> imp <- mice(nhanes2.ext, meth = meth, pred = pred, seed = 38788,

+ print = FALSE)

R> head(complete(imp))

age bmi hyp chl lchl

1 20-39 35.3 no 218 5.384495

2 40-59 22.7 no 187 5.231109

3 20-39 30.1 no 187 5.231109

4 60-99 22.5 yes 218 5.384495

5 20-39 20.4 no 113 4.727388

6 60-99 22.7 no 184 5.214936

We deﬁned the predictor matrix such that either chl or log(chl) is a predictor, but not both

at the same time, primarily to avoid collinearity. Moreover, we do not want to predict chl

from lchl. Doing so would immobilize the MICE algorithm at the starting imputation. It

is thus important to set the entry pred["chl", "lchl"] equal to zero to avoid this. After

running mice() we ﬁnd imputations for both chl and lchl that respect the relation.

Note: A slightly easier way to create nhanes2.ext is to specify

R> nhanes2.ext <- cbind(nhanes2, lchl = NA)

followed by the same commands. This has the advantage that the transform needs to be

speciﬁed only once. Since all values in lchl are now treated as missing, the size of imp will

generally become (much) larger however. The ﬁrst method is generally more eﬃcient, but the

second is easier.

Index of two variables

The idea can be extended to two or more columns. This is useful to create derived variables

that should remain synchronized. As an example, we consider imputation of body mass index

(bmi), which is deﬁned as weight divided by height*height. It is impossible to calculate bmi

if either weight or height is missing. Consider the data boys in mice.

R> md.pattern(boys[, c("hgt", "wgt", "bmi")])

wgt hgt bmi

727 1 1 1 0

17 1 0 0 2

10102

30003

4 20 21 45

Data on weight and height are missing for 4 and 20 cases, respectively, resulting in 21 cases

for which bmi could not be calculated. Using passive imputation, we can impute bmi from

height and weight by means of the I() operator.

Journal of Statistical Software 27

R> ini <- mice(boys, max = 0, print = FALSE)

R> meth <- ini$meth

R> meth["bmi"] <- "~I(wgt/(hgt/100)^2)"

R> pred <- ini$pred

R> pred[c("wgt", "hgt", "hc", "reg"), "bmi"] <- 0

R> pred[c("gen", "phb", "tv"), c("hgt", "wgt", "hc")] <- 0

R> pred

age hgt wgt bmi hc gen phb tv reg

age000000000

hgt101011111

wgt110011111

bmi111011111

hc 111001111

gen100100111

phb100101011

tv 100101101

reg111011110

The predictor matrix prevents that hgt or wgt are imputed from bmi, and takes care that

there are no cases where hgt,wgt and bmi are simultaneous predictors. Passive imputation

overrules the selection of variables speciﬁed in the predictorMatrix argument. Thus, in

the above case, we might have well set pred["bmi",] <- 0 and obtain identical results.

Imputations can now be created by

R> imp.idx <- mice(boys, pred = pred, meth = meth, maxit = 20,

+ seed = 9212, print = FALSE)

R> head(complete(imp.idx)[is.na(boys$bmi), ], 3)

age hgt wgt bmi hc gen phb tv reg

103 0.087 60.0 4.54 12.61111 39.0 G1 P1 3 west

366 0.177 57.5 4.20 12.70321 40.4 G1 P1 1 west

1617 1.481 85.5 12.04 16.47002 47.5 G1 P1 1 north

Observe than the imputed values for bmi are consistent with (imputed) values of hgt and wgt.

Note: The values of bmi in the original data have been rounded to two decimals. If desired,

one can get that also in the imputed values by setting

R> meth["bmi"] <- "~round(wgt/(hgt/100)^2,dig=2)"

Sum scores

The sum score is undeﬁned if one of the variables to be added is missing. We can use

sum scores of imputed variables within the MICE algorithm to economize on the number

of predictors. For example, suppose we create a summary maturation score of the pubertal

measurements gen,phb and tv, and use that score to impute the other variables instead of

the three original pubertal measurements. We can achieve that by

28 mice: Multivariate Imputation by Chained Equations in R

R> ini <- mice(cbind(boys, mat = NA), max = 0, print = FALSE)

R> meth <- ini$meth

R> meth["mat"] <- "~I(as.integer(gen) + as.integer(phb) +\n

+ + as.integer(cut(tv,breaks=c(0,3,6,10,15,20,25))))"

R> meth["bmi"] <- "~I(wgt/(hgt/100)^2)"

R> pred <- ini$pred

R> pred[c("bmi", "gen", "phb", "tv"), "mat"] <- 0

R> pred[c("hgt", "wgt", "hc", "reg"), "mat"] <- 1

R> pred[c("hgt", "wgt", "hc", "reg"), c("gen", "phb", "tv")] <- 0

R> pred[c("wgt", "hgt", "hc", "reg"), "bmi"] <- 0

R> pred[c("gen", "phb", "tv"), c("hgt", "wgt", "hc")] <- 0

R> pred

age hgt wgt bmi hc gen phb tv reg mat

age0000000000

hgt1010100011

wgt1100100011

bmi1110111110

hc 1110000011

gen1001001110

phb1001010110

tv 1001011010

reg1110100001

mat0000000000

The maturation score mat is composed of the sum of gen,phb and tv. Since the ﬁrst two are

factors, we need the as.integer() function to get the internal numerical codes. Furthermore,

we recoded tv into 6 ordered categories by calling the cut() function, and use the category

number to calculate the sum score. The predictor matrix is set up so that either the set of

(gen,phb,tv) or mat are predictors, but never at the same time. The number of predictors

for say, hgt, has now dropped from 8 to 5, but imputation still incorporates the main relations

of interest. Imputations can now be generated and plotted by

R> imp.sum <- mice(cbind(boys, mat = NA), pred = pred, meth = meth,

+ maxit = 20, seed = 10948, print = FALSE)

R> xyplot(imp.sum, mat ~ age | .imp, na = gen | phb | tv,

+ subset = .imp == 1, ylab = "Maturation score", xlab = "Age (years)")

Figure 5plots the derived maturation scores against age. Since no measurements were made

before the age of 8 years, all scores on the left side are sums of three imputed values for

gen,phb and tv. Note that imputation relies on extreme extrapolation outside the range of

the data. Though quite a few anomalies are present (many babies score a ‘4’ or higher), the

overall pattern is as expected. Section 3.5 discusses ways to improve the imputations.

Interaction terms

In some cases scientiﬁc interest focusses on interactions terms. For example, in experimental

studies we may be interested in assessing whether the rate of change diﬀers between two

Journal of Statistical Software 29

Age (years)

Maturation score

5

10

15

0 5 10 15 20

1

Figure 5: Observed (blue) and (partially) imputed (red) maturation scores plotted against

age.

treatment groups. In such cases, the primary goal is to get an unbiased estimate of the time

by group interaction. In general imputations should be </