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

syn.formula

Synthesizing Method for synthpop Using a Formula Interface


Description

Defines a synthesizing method for for synthpop using a formula interface.

Usage

syn.formula(y, x, xp, proper=FALSE, syn_formula, syn_fun, syn_args, ...)

Arguments

y

Original data vector of length n

x

Matrix (n \times p) of original covariates

xp

Matrix (k \times p) of synthesised covariates

proper

Logical value specifying whether proper synthesis should be conducted.

syn_formula

A formula object

syn_fun

Synthesizing method in synthpop package

syn_args

Function arguments of syn_fun

...

Further arguments to be passed

Details

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

Value

A vector of length k with synthetic values of y.

See Also

Examples

## Not run: 
#############################################################################
# EXAMPLE 1: SD2011 | using a formula for defining the regression model
#############################################################################

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 synthesizing method 'formula'
method["ls"] <- "formula"
syn_fun <- list( ls="normrank" )
syn_args <- list( ls=list( smoothing="density" ) )
syn_formula <- list( ls=~ sex + age + I(age^2) + I(age>50) )

#* synthesize data
imp <- synthpop::syn( dat, method=method, predictor.matrix=pred, k=2000, m=1,
            rf.syn_fun=syn_fun, rf.syn_args=syn_args, rf.syn_formula=syn_formula)
summary(imp)

## 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.