Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

syn.mice

Using a mice Imputation Method in the synthpop Package


Description

The function allows to use a mice imputation method to be used in the synthpop::syn function of the synthpop package (Nowok, Raab, & Dibben, 2016).

Usage

syn.mice(y, x, xp, mice_fun, mice_arg, ...)

Arguments

y

Original data vector of length n

x

Matrix (n \times p) of original covariates

xp

Matrix (k \times p) of synthesised covariates

mice_fun

Name of imputation method for mice

mice_arg

Optional list of arguments for mice_fun, see Examples.

...

Further arguments to be passed

Details

When using the synthesis method "mice" in synthpop::syn, the function arguments have to appear as rf.mice_fun and rf.mice_arg (convention in synthpop).

Value

A vector of length k with synthetic values of y.

References

Nowok, B., Raab, G., & Dibben, C. (2016). synthpop: Bespoke creation of synthetic data in R. Journal of Statistical Software, 74(11), 1-26. doi: 10.18637/jss.v074.i11

See Also

Examples

## Not run: 
#############################################################################
# EXAMPLE 1: SD2011 | Minimal example for using a mice imputation method
#############################################################################

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)
pred <- imp0$predictor.matrix
method <- imp0$method

#** use mice imputation method 'rlm' for variable 'ls'
method["ls"] <- "mice"
mice_fun <- list( ls="rlm" )
mice_args <- list( ls=list( trafo=base::log, antitrafo=base::exp) )

#* synthesize data
imp <- synthpop::syn( dat, method=method, predictor.matrix=pred, k=2000, m=1,
            rf.mice_fun=mice_fun, rf.mice_args=mice_args)
str(imp$syn)

## End(Not run)

miceadds

Some Additional Multiple Imputation Functions, Especially for 'mice'

v3.11-6
GPL (>= 2)
Authors
Alexander Robitzsch [aut,cre] (<https://orcid.org/0000-0002-8226-3132>), Simon Grund [aut] (<https://orcid.org/0000-0002-1290-8986>), Thorsten Henke [ctb]
Initial release
2021-01-21 11:48:47

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.