R: Imputation of a Variable with a Known Posterior Distribution
mice.impute.2l.eap
R Documentation
Imputation of a Variable with a Known Posterior Distribution
Description
This function imputes values of a variable for which the
mean and the standard deviation of the posterior distribution
is known.
Usage
mice.impute.2l.eap(y, ry, x, eap, ...)
Arguments
y
Incomplete data vector of length n
ry
Vector of missing data pattern (FALSE – missing,
TRUE – observed)
x
Matrix (n x p) of complete covariates.
eap
List with means and standard deviations of the posterior distribution
(see Examples). If for multiple variables posterior distributions are
known, then it is a list named in which each list entry is named according
th variable to be imputed and each list entry contains the variable's
EAP and standard deviation of the EAP.
...
Further arguments to be passed
Value
A vector of length nmis=sum(!ry) with imputed values.
Author(s)
Alexander Robitzsch
Examples
## Not run:
#############################################################################
# EXAMPLE 1: Imputation based on known posterior distribution
#############################################################################
data(data.ma03)
dat <- data.ma03
# definiere variable 'math_PV' as the plausible value imputation of math
dat$math_PV <- NA
vars <- colnames(dat)
dat1 <- as.matrix( dat[,vars] )
# define imputation methods
impmethod <- rep( "pmm" , length(vars ))
names(impmethod) <- vars
# define plausible value imputation based on EAP and SEEAP for 'math_PV'
impmethod[ "math_PV" ] <- "2l.eap"
eap <- list( "math_PV" = list( "M" = dat$math_EAP , "SE" = dat$math_SEEAP ) )
# define predictor matrix
pM <- 1 - diag(1,length(vars))
rownames(pM) <- colnames(pM) <- vars
pM[,c("idstud","math_EAP" , "math_SEEAP") ] <- 0
# remove some variables from imputation model
# imputation using three parallel chains
imp1 <- mice::mice( dat1 , m=3 , maxit=5 , imputationMethod=impmethod ,
predictorMatrix = pM , allow.na =TRUE , eap=eap )
summary(imp1) # summary
# imputation using one long chain
imp2 <- mice.1chain( dat1 , burnin=10 , iter=20 , Nimp =3 , imputationMethod=impmethod ,
predictorMatrix = pM , allow.na =TRUE , eap=eap )
summary(imp2) # summary
## End(Not run)