if (FALSE) {
#############################################################################
# EXAMPLE 1: Synthesization of SD2011 using mice functionality
#############################################################################
library(synthpop)
#** selection of dataset
data(SD2011, package="synthpop")
vars <- c("sex","age","ls","smoke")
dat <- SD2011[1:1000, vars]
dat$ls <- as.numeric(dat$ls)
#** default synthesis
imp0 <- synthpop::syn(dat)
pred0 <- imp0$predictor.matrix
method0 <- imp0$method
#* define imputation methods
method <- c(sex="synthpop", age="synthpop", ls="synthpop", smoke="logreg")
# only for smoke, an original mice imputation method is used
#- define synthpop functions
synthpop_fun <- list(sex="constant", age="constant", ls="cart")
#- arguments for 'syn.cart' method
synthpop_args <- list(ls=list(smoothing="density"))
#- fixed values for 'syn.constant' method
fixed_values <- dat[,1:2]
#- do synthesization
imp <- miceadds::syn_mice(dat, m=1, synthpop_fun=synthpop_fun, method=method,
pedictorMatrix=pred0, rf.fixed_values=fixed_values, synthpop_args=synthpop_args)
summary(imp)
}
Run the code above in your browser using DataLab