syn.constant | R Documentation |
Defines a synthesizing method for fixed values of a variable by design in the synthpop package.
syn.constant(y, x, xp, fixed_values, ...)
y |
Original data vector of length |
x |
Matrix ( |
xp |
Matrix ( |
fixed_values |
Vector containing fixed values |
... |
Further arguments to be passed |
When using the synthesis method "mice"
in
synthpop::syn
, the function argument has to appear
as rf.fixed_values
(convention in synthpop).
A vector of length k
with synthetic values of y
.
synthpop::syn
,
mice.impute.constant
## Not run:
#############################################################################
# EXAMPLE 1: SD2011 | Fixed values for variable sex
#############################################################################
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
#** constant vector
method["sex"] <- "constant"
fixed_values <- data.frame( sex=rep(dat$sex[c(1,2)], each=1000) )
imp <- synthpop::syn( dat, method=method, k=2000, m=1,
rf.fixed_values=fixed_values)
table(imp$syn$sex)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.