I want to print the output from densityplot()
from the mice
package (densityplot
method for mids
objects), each to a separate page on a PDF. For the MWE below, I want to print one plot on each page (i.e., bmi on page 1, then hyp on page 2, then chi on page 3).
library(mice)
imp <- mice(nhanes)
densityplot(imp)
EDIT:
My slightly modified solution (to do this programatically):
# Which variables had missing observations
imputed_vars <- names(d_imp$method)[d_imp$method != ""]
pdf(file = "./MICE Density Plots.pdf")
# Plot each imputed variable separately
for(var in imputed_vars){
densityplot(d_imp, formula(paste("~", var)))
}
dev.off()
you mean something like this:
imp <- mice(nhanes)
densityplot(imp)
densityplot(imp, ~bmi)
densityplot(imp, ~hyp)
densityplot(imp, ~chl)
BR