## Not run:
# library(mice)
# library(miceadds)
#
# #############################################################################
# # EXAMPLE 1: Categorize questionnaire data
# #############################################################################
#
# data(data.smallscale , package="miceadds")
# dat <- data.smallscale
#
# # (0) select dataset
# dat <- dat[ , 9:20 ]
# summary(dat)
# categorical <- colnames(dat)[2:6]
#
# # (1) categorize data
# res <- categorize( dat , categorical=categorical )
#
# # (2) multiple imputation using the mice package
# dat2 <- res$data
# VV <- ncol(dat2)
# impMethod <- rep( "sample" , VV ) # define random sampling imputation method
# names(impMethod) <- colnames(dat2)
# imp <- mice::mice( as.matrix(dat2) , impMethod = impMethod , maxit=1 , m=1 )
# dat3 <- mice::complete(imp,action=1)
#
# # (3) decategorize dataset
# dat3a <- decategorize( dat3 , categ_design = res$categ_design )
#
# #############################################################################
# # EXAMPLE 2: Categorize ordinal and continuous data
# #############################################################################
#
# data(data.ma01,package="miceadds")
# dat <- data.ma01
# summary(dat[,-c(1:2)] )
#
# # define variables to be categorized
# categorical <- c("books" , "paredu" )
# # define quantiles
# quant <- c(6,5,11)
# names(quant) <- c("math" , "read" , "hisei")
#
# # categorize data
# res <- categorize( dat , categorical = categorical , quant=quant)
# str(res)
# ## End(Not run)
Run the code above in your browser using DataLab