Learn R Programming

miceadds (version 2.2-0)

datlist_create: Creates Objects of Class datlist or nested.datlist

Description

Creates objects of class datlist or nested.datlist.

The functions nested.datlist2datlist and datlist2nested.datlist provide list conversions for imputed datasets.

Usage

datlist_create(datasets)
nested.datlist_create(datasets)
"print"(x, ...)
"print"(x, ...)
nested.datlist2datlist(datlist)
datlist2nested.datlist(datlist, Nimp)

Arguments

datasets
For datlist_create: List of datasets, objects of class imputationList, mids, mids.1chain,

For nested.datlist_create: nested list of datasets, NestedImputationList, mids.nmi

x
Object of classes datlist or nested.datlist
datlist
Object of classes datlist, imputationList, nested.datlist or NestedImputationList.
Nimp
Vector of length 2 containing numbers of between and within imputations.
...
Further arguments to be passed

Value

Object of class datlist or nested.datlist

Examples

Run this code
## Not run: 
# ## The function datlist_create is currently defined as
# function (datasets) 
# {
#     class(datasets) <- "datlist"
#     return(datasets)
#   }
#   
# #############################################################################
# # EXAMPLE 1: Create object of class datlist
# #############################################################################
# 
# library(BIFIEsurvey)
# data(data.timss2 , package="BIFIEsurvey" )
# datlist <- data.timss2      
# 
# # class datlist
# obj1 <- datlist_create(data.timss2)
# 
# #############################################################################
# # EXAMPLE 2: Multiply imputed datasets: Different object classes
# #############################################################################
# 
# library(mice)
# data(nhanes2, package="mice")
# set.seed(990)
# 
# # nhanes2 data imputation
# imp1 <- mice.1chain( nhanes2 , burnin=5 , iter=25 , Nimp=5 )
# # object of class datlist
# imp2 <- mids2datlist(imp1)
# # alternatively, one can use datlist_create
# imp2b <- datlist_create(imp1)
# # object of class imputationList
# imp3 <- mitools::imputationList(imp2)
# # retransform object in class datlist
# imp2c <- datlist_create(imp3)
# str(imp2c)
# 
# #############################################################################
# # EXAMPLE 3: Nested multiply imputed datasets
# #############################################################################
# 
# library(BIFIEsurvey)
# data(data.timss2 , package="BIFIEsurvey" )
# datlist <- data.timss2      
#    # list of 5 datasets containing 5 plausible values
# 
# #** define imputation method and predictor matrix
# data <- datlist[[1]]
# V <- ncol(data)
# # variables
# vars <- colnames(data)
# # variables not used for imputation
# vars_unused <- scan.vec("IDSTUD TOTWGT  JKZONE  JKREP" )
# 
# #- define imputation method
# impMethod <- rep("norm" , V )
# names(impMethod) <- vars
# impMethod[ vars_unused ] <- ""
# 
# #- define predictor matrix
# predM <- matrix( 1 , V , V )
# colnames(predM) <- rownames(predM) <- vars
# diag(predM) <- 0
# predM[ , vars_unused ] <- 0
# 
# # object of class nmi
# imp1 <- mice.nmi( datlist , imputationMethod=impMethod , predictorMatrix=predM, 
#                 m=4 , maxit=3 )
# # object of class nested.datlist
# imp2 <- mids2datlist(imp1)
# # object of class NestedImputationList
# imp3 <- NestedImputationList(imp2)
# # redefine class nested.datlist
# imp4 <- nested.datlist_create(imp3)
# 
# #############################################################################
# # EXAMPLE 4: Conversions between nested lists of datasets and lists of datasets
# #############################################################################
# 
# library(BIFIEsurvey)
# data(data.timss4 , package="BIFIEsurvey" )
# datlist <- data.timss4
# 
# # object of class nested.datlist
# datlist1a <- nested.datlist_create(datlist)
# # object of class NestedImputationList
# datlist1b <- NestedImputationList(datlist)
# 
# # conversion to datlist
# datlist2a <- nested.datlist2datlist(datlist1a)  # class datlist
# datlist2b <- nested.datlist2datlist(datlist1b)  # class imputationList
# 
# # convert into a nested list with 2 between nests and 10 within nests
# datlist3a <- datlist2nested.datlist(datlist2a, Nimp=c(2,10) )
# datlist3b <- datlist2nested.datlist(datlist2b, Nimp=c(4,5) )
# ## End(Not run)  

Run the code above in your browser using DataLab