# 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" ] <- "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, method=impmethod,
predictorMatrix=pM, allow.na=TRUE, eap=eap )
summary(imp1) # summary
# imputation using one long chain
imp2 <- miceadds::mice.1chain( dat1, burnin=10, iter=20, Nimp=3,
method=impmethod, predictorMatrix=pM, allow.na=TRUE, eap=eap)
summary(imp2) # summary
# }
Run the code above in your browser using DataLab