## Not run:
# #############################################################################
# # EXAMPLE 1: PLS imputation method for internet data
# #############################################################################
#
# data(data.internet)
# dat <- data.internet
#
# # specify predictor matrix
# predictorMatrix <- matrix( 1 , ncol(dat) , ncol(dat) )
# rownames(predictorMatrix) <- colnames(predictorMatrix) <- colnames(dat)
# diag( predictorMatrix) <- 0
#
# # use PLS imputation method for all variables
# impMethod <- rep( "pls" , ncol(dat) )
# names(impMethod) <- colnames(dat)
#
# # define predictors for interactions (entries with type 4 in predictorMatrix)
# predictorMatrix[c("IN1","IN15","IN16"),c("IN1","IN3","IN10","IN13")] <- 4
# # define predictors which should appear as linear and quadratic terms (type 5)
# predictorMatrix[c("IN1","IN8","IN9","IN10","IN11"),c("IN1","IN2","IN7","IN5")] <- 5
#
# # use 9 PLS factors for all variables
# pls.facs <- as.list( rep( 9 , length(impMethod) ) )
# names(pls.facs) <- names(impMethod)
# pls.facs$IN1 <- 15 # use 15 PLS factors for variable IN1
#
# # choose norm or pmm imputation method
# pls.impMethod <- as.list( rep("norm" , length(impMethod) ) )
# names(pls.impMethod) <- names(impMethod)
# pls.impMethod[ c("IN1","IN6")] <- "pmm5"
#
# # some arguments for imputation method
# pls.impMethodArgs <- list( "IN1" = list( "donors" = 10 ) ,
# "IN2" = list( "ridge2" = 1E-4 ) )
#
# # Model 1: Three parallel chains
# imp1 <- mice::mice(data = dat , imputationMethod = impMethod ,
# m=3 , maxit=5 , predictorMatrix = predictorMatrix ,
# pls.facs = pls.facs , # number of PLS factors
# pls.impMethod = pls.impMethod , # Imputation Method in PLS imputation
# pls.impMethodArgs = pls.impMethodArgs , # arguments for imputation method
# pls.print.progress = TRUE )
# summary(imp1)
#
# # Model 2: One long chain
# imp2 <- mice.1chain(data = dat , imputationMethod = impMethod ,
# burnin=10 , iter=21 , Nimp=3 , predictorMatrix = predictorMatrix ,
# pls.facs = pls.facs , pls.impMethod = pls.impMethod ,
# pls.impMethodArgs = pls.impMethodArgs )
# summary(imp2)
# ## End(Not run)
Run the code above in your browser using DataLab