Multiple Imputation in R: A Reproducible mice Workflow

Multiple imputation in R means creating several completed copies of your dataset, each with plausible values filled in for the missing entries. You then run your analysis on every copy and pool the results with Rubin’s rules. In practice this is the mice package, a handful of functions (mice(), with(), pool()), and a set of decisions that reviewers will ask you to justify. This guide covers the code and those decisions, in the order you meet them. It also shows where agentic analytics for researchers, which is what PlotStudio AI provides, fits around R by planning, running and documenting the workflow so a supervisor can inspect it.
TL;DR
- Multiple imputation is justified by an assumption (usually missing at random given the variables you include), not by a property of the data. State the assumption and defend it.
- The imputation model must contain every variable in your analysis model, including the outcome, plus variables that predict missingness or the missing values.
- The standard loop is
mice(), thenwith(), thenpool(). Choose the number of imputations from the fraction of missing information, not by habit. - Check convergence and plausibility with trace plots and density plots, then report the method, variables, number of imputations and software.
- PlotStudio AI adds an agentic layer on top of R and Python: a reviewable plan, executed code, and a preserved record of the analysis.
Table of Contents
- Decide first whether multiple imputation fits your data
- Step 1: Build a small, deliberate dataset
- Step 2: Choose imputation methods and the predictor matrix
- Step 3: Run mice with a seed
- Step 4: Check convergence and plausibility
- Step 5: Analyze each dataset and pool with Rubin’s rules
- Step 6: Report it so it can be reproduced
- Where the workflow breaks under deadline pressure
- Adding an agentic layer to your R workflow
- Try PlotStudio AI on your own dataset
- Our perspective
- FAQ
- Sources
Decide first whether multiple imputation fits your data
The code takes ten minutes. The justification is what a reviewer reads closely, so start there.
The TARMOS framework, written by members of the STRATOS initiative, advises asking whether multiple imputation is likely to offer benefits in your setting. It depends on how much information is missing, whether you have auxiliary variables (variables correlated with the incomplete ones that are not in your analysis model), and which variables are incomplete. The gain is largest when the outcome and exposure are complete but confounders are incomplete. It is small when only the outcome is missing and you have no auxiliary variables.
Then name the missing-data mechanism you are assuming:
- Missing completely at random (MCAR): missingness is unrelated to anything, observed or not.
- Missing at random (MAR): given the variables you have observed, missingness does not depend on the unobserved value itself.
- Missing not at random (MNAR): missingness depends on the unobserved value even after accounting for observed data.
Most multiple imputation software assumes MAR given the variables in the imputation model. Hughes and colleagues (2019) note that multiple imputation generally gives biased results under MNAR, and that complete-case analysis can then be preferable. Sterne and colleagues (2009) make the point that MAR is an assumption that justifies the analysis, not a property of the data. It can be reasonable if a variable predictive of missingness is in the imputation model and unreasonable if you leave it out.
For a more formal route, Lee and colleagues (2023) describe planning around recoverability. If your target parameter is recoverable from the observed data, standard multiple imputation can reduce bias or improve precision. If it is not, you need a delta-adjusted (pattern-mixture) analysis, where a missingness-indicator term with expert-specified delta coefficients enters the imputation model. That is a sensitivity analysis, and it is the answer to the reviewer who asks, “What if the missing values are systematically different?”
For a broader view of when to impute, delete or model missingness directly, see our guide on how to handle missing data.
Step 1: Build a small, deliberate dataset
Do not feed mice() your entire raw export. The University of Zurich EBPI guide recommends preparing a reduced dataset that contains your analysis variables and the variables related to missingness, and setting a seed so the run can be repeated.
The variables to include follow Hughes and colleagues:
- Every variable in the analysis model, including the outcome.
- Variables that predict which values are missing.
- Variables that predict the incomplete values themselves (auxiliary variables).
The imputation model also has to be compatible with the substantive model. TARMOS advises that the variables, their forms and any interactions in the analysis model be reflected in the imputation model. If you will fit a quadratic age term or a treatment-by-sex interaction, the imputation step needs to know.
Two practical checks before you run anything:
- Convert categorical variables to factors. A binary variable stored as numeric is imputed as if it were continuous.
- Remove identifiers, free-text fields and near-duplicate columns. They add noise and can break the predictor matrix.
library(mice)
dat <- dat[, c("outcome", "exposure", "age", "sex", "bmi", "site", "aux1")]
dat$sex <- factor(dat$sex)
dat$site <- factor(dat$site)
md.pattern(dat) # how many cases share each missingness pattern
md.pattern() shows which combinations of variables are missing together. If a variable is missing almost entirely, imputing it is guesswork, and you should say so in your methods.
Step 2: Choose imputation methods and the predictor matrix
By default, mice() picks a method for each incomplete column from its type. According to the EBPI guide, the defaults are predictive mean matching (pmm) for numeric variables and polyreg for categorical variables with more than two levels. Recoding a binary variable as a factor gives the logreg default.
Predictive mean matching imputes by borrowing observed values from cases with similar predicted values. That keeps imputations within the range of real data, which is useful for skewed variables.
A dry run with maxit = 0 lets you inspect and edit the defaults before any imputation happens:
ini <- mice(dat, maxit = 0)
meth <- ini$method
pred <- ini$predictorMatrix
meth # one method per column
pred # rows = variable being imputed, columns = predictors
In the predictor matrix, a 1 means the column is used to predict the row’s variable. Edit it when you have a reason: drop an identifier, or break a feedback loop. Van Buuren notes in Flexible Imputation of Missing Data that feedback loops (for example, body mass index feeding height and weight, which feed it back) can cause non-convergence, and that zeroing the relevant entries in the predictor matrix fixes it.
If your analysis has a derived variable, such as BMI computed from height and weight, or an interaction, decide how it will be imputed and document that choice. Passive imputation and imputing the components first are both defensible, but only if the imputation model stays compatible with the analysis model.

Step 3: Run mice with a seed
imp <- mice(dat,
m = 5,
maxit = 20,
method = meth,
predictorMatrix = pred,
seed = 2026,
printFlag = FALSE)
m is the number of completed datasets. maxit is the number of iterations of the chained-equations algorithm per dataset. The seed makes the run repeatable, which is the first thing a supervisor who cannot reproduce your numbers needs.
How many imputations?
Five was the long-standing habit, and it is a starting point. The EBPI guide describes a two-stage procedure:
- Run
mice()withm = 5and pool a model containing all your variables. - Inspect the
fmicolumn (the fraction of missing information) in the pooled output. - Round the highest
fmiup to the nearest 0.05 and multiply by 100. Anfmiof 0.236 givesm = 25. - Rerun
mice()with thatm.
The same guide cites von Hippel’s two-stage approach, implemented in the R package howManyImputations. Its worked example, how_many_imputations(mod, cv = 0.05), returned 179. The number varies a lot with how much information is missing, so compute it for your data and report it.
Step 4: Check convergence and plausibility
A run that finishes is not a run that has converged. Van Buuren states that there is no clear-cut method for determining convergence of the chained-equations algorithm. The usual first look is the trace plot:
plot(imp)
This plots the mean and standard deviation of the imputed values per variable, one line per parallel stream. You want the streams to intermingle with no definite trend, and the variance between streams to be no larger than the variance within them. Van Buuren adds that Cowles and Carlin (1996) concluded automated convergence monitoring is unsafe, so the consensus is to combine several tools. He also points to alternative monitored quantities, such as a statistic of scientific interest like a correlation or a proportion.
Then compare imputed values with observed ones:
densityplot(imp) # observed vs imputed distributions
stripplot(imp, bmi ~ .imp) # individual imputed points
bwplot(imp) # box-and-whisker comparison
Imputed distributions do not have to match observed ones exactly. If missingness depends on other variables, they can differ legitimately. But a variable whose imputed values sit far outside the observed range deserves an explanation, such as a wrong variable type, an unmodeled interaction or a missing auxiliary variable.
Step 5: Analyze each dataset and pool with Rubin’s rules
The rest of the workflow is three verbs, as the EBPI guide lays out: mice() makes the copies and fills the missing values, with() analyzes each completed dataset, and pool() combines the parameter estimates using Rubin’s rules. Rubin’s rules average the estimates across datasets and combine the within-imputation and between-imputation variance, so the standard errors reflect the uncertainty that imputation adds.
fit <- with(imp, lm(outcome ~ exposure + age + sex + bmi + site))
pooled <- pool(fit)
summary(pooled, conf.int = TRUE)
The pool() function works for most model types as long as a tidy method exists in the broom or broom.mixed package. That covers linear and generalized linear models, and mixed models through broom.mixed. For repeated-measures designs, see our guide to longitudinal data analysis.
Two mistakes recur in submitted manuscripts:
- Averaging first, analyzing second. Averaging the imputed datasets into one and fitting a single model discards the between-imputation variance, and your standard errors come out too small.
- Dropping the outcome from the imputation model. The outcome belongs in it. Imputing predictors without the outcome biases associations toward zero.
Step 6: Report it so it can be reproduced
TARMOS recommends reporting the imputation method, the variables included, the forms of those variables, the relationships modeled (including nonlinear terms and interactions), the number of imputations, and the software used. A methods paragraph that covers this:
Missing data were handled by multiple imputation using chained equations (
mice, R version X.X, package version X.X). The imputation model included all analysis variables, the outcome, and [auxiliary variables]. Continuous variables were imputed by predictive mean matching. We generated [m] imputed datasets, determined from the fraction of missing information, with [maxit] iterations each and seed [seed]. Convergence was assessed with trace plots. Estimates were pooled using Rubin’s rules.
Add a sensitivity analysis if MAR is doubtful. If a reviewer pushes on the assumption, a delta-adjusted analysis in the spirit of Lee and colleagues answers the question directly.
For a reviewer-oriented walkthrough of how to present these choices, our article on missing data imputation for researchers goes further.
Where the workflow breaks under deadline pressure
The mechanics are short. The failures are about everything around them:
- The script that produced the pooled table was edited after the figures were made, and nobody remembers which seed was used.
- The imputation model and the analysis model drift apart when a covariate is added late.
- A supervisor asks why
mis 25 and not 5, and the reasoning lives in someone’s head. - Clinical data cannot leave the machine, so any tool that needs an upload is out.
These are documentation and review problems, not statistical ones. That is the gap an agentic layer addresses.
Adding an agentic layer to your R workflow
R, Python and Jupyter provide the statistical computing. PlotStudio AI is agentic analytics for researchers: specialized AI agents plan an investigation, write and run real code, inspect intermediate results and synthesize the findings into a reproducible analysis. It sits alongside your existing tools and does not replace them.
For a multiple-imputation project, these are the features that matter:
- Plan Mode. You review and modify the proposed analytical approach before execution, including the methods, assumptions and steps the agent intends to perform. That is the point at which to check that the imputation model includes the outcome and your interaction terms.
- Python and R workflows. The platform supports both, and is designed for the methods researchers use regularly, including regression, mixed-effects models, survival analysis, Cox proportional hazards models and multiple-comparison procedures.
- Local execution. Analyses can run locally on your machine, which suits privacy-sensitive work where datasets should not be uploaded to conventional cloud analytics platforms.
- Skills. Domain-specific Skills encode how a lab or discipline approaches analysis, including required procedures, statistical conventions and reporting expectations. A group can encode its own missing-data conventions once.
- Analysis Pages and exports. Completed work is preserved as searchable Analysis Pages and can be exported as notebooks and PDF reports, so collaborators and supervisors can inspect how results were produced.
That last point answers the supervisor who cannot reproduce your numbers: the methodology, code, outputs and statistics are available for review rather than reconstructed from memory. More on this approach is in our data analysis with LLM articles.
Try PlotStudio AI on your own dataset
PlotStudio AI offers a Free Trial, with no published price, so you can run a real analysis before you commit. The paid plans are Bring Your Own Key at $39.99 per month, or $399.90 per year on the academic plan, and Managed Credits at $69.99 per month. Details for each are on the pricing page. Research groups looking at managed deployments can find the $500 one-off pilot fee on the enterprise page.

If your next step is an imputation analysis with a deadline attached, start with the plan: write down your missing-data assumption, the variables in the imputation model and the number of imputations, and review it before anything runs.
Our perspective
Most imputation problems we see described by researchers are not coding problems.
mice()runs. What fails is the chain of reasoning around it: why this imputation model, why this many imputations, why MAR is believable, and whether anyone else can reproduce the pooled table.That is why we built PlotStudio AI around the full research workflow rather than one-shot answers. Agentic analytics for researchers means an agent that plans a multi-step investigation, runs real code, inspects intermediate results and keeps the methodology, code, statistics and charts together for review. Plan Mode puts the researcher in charge of the approach before execution, and Skills let a lab encode its own conventions, such as how it documents missing-data assumptions.
We see PlotStudio AI as an emerging must-have layer in the modern research toolkit, next to R, Python and Jupyter. Those tools provide statistical computing. PlotStudio AI adds a layer that can plan, execute, inspect, validate and document a complete analysis, so that a reviewer or supervisor can follow every step.
Aymen
FAQ
How many imputed datasets do I need in R?
Five is the default starting point, not a target. The EBPI guide suggests running mice() with m = 5, pooling a model, and taking the highest fraction of missing information rounded up to the nearest 0.05, multiplied by 100. An fmi of 0.236 gives 25 imputations. Then rerun mice() with that value.
Can I use multiple imputation if the data are missing not at random?
Standard implementations assume MAR given the variables in the imputation model, so they can give biased results under MNAR. In that case, Hughes and colleagues note that complete-case analysis can be preferable. A delta-adjusted sensitivity analysis lets you test how conclusions change under specified departures from MAR.
Should the outcome be in the imputation model?
Yes. Imputation models should contain all variables in the analysis model, including the outcome, plus variables that predict missingness and variables that predict the incomplete values. Leaving the outcome out biases the associations you are trying to estimate.
How do I know mice has converged?
There is no single test. Use plot(imp) and look for streams that intermingle without trends, with between-stream variance no larger than within-stream variance. Combine that with density and strip plots of imputed against observed values. Van Buuren cautions against relying on automated convergence monitoring alone.
What should I put in the methods section?
Report the imputation method, the variables included and their forms, any nonlinear terms and interactions, the number of imputations and the software, as TARMOS recommends. Add the seed and the number of iterations so the run can be repeated.
Sources
- Framework for the treatment and reporting of missing data (TARMOS), 2021
- Hughes et al., Accounting for missing data in statistical analyses, 2019
- Sterne et al., Multiple imputation for missing data in epidemiological and clinical research, 2009
- Lee et al., Assumptions and analysis planning in studies with missing data, International Journal of Epidemiology, 2023
- University of Zurich EBPI, Introduction to multiple imputation, revised April 2026
- Van Buuren, Flexible Imputation of Missing Data, algorithmic options and convergence