Description Usage Arguments Value Note Author(s) See Also Examples
View source: R/subset_datlist.R
Returns a subsets of multiply imputed datasets or nested multiply imputed datasets.
These function allows choosing parts of the imputed datasets using the
index
argument for multiply imputed datasets and index_between
and
index_within
for nested multiply imputed datasets as well as the application
of the base::subset
S3 method for selecting
cases and variables in datasets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | subset_datlist(datlist, subset = TRUE, select = NULL, expr_subset = NULL ,
index = NULL, toclass = "datlist")
## S3 method for class 'datlist'
subset(x, subset, select = NULL, expr_subset = NULL ,
index = NULL , ...)
## S3 method for class 'imputationList'
subset(x, subset, select = NULL, expr_subset = NULL ,
index = NULL , ...)
## S3 method for class 'mids'
subset(x, subset, select = NULL, expr_subset = NULL,
index = NULL , ...)
## S3 method for class 'mids.1chain'
subset(x, subset, select = NULL, expr_subset = NULL ,
index = NULL , ...)
subset_nested.datlist( datlist , subset = TRUE, select = NULL , expr_subset = NULL,
index_between = NULL , index_within = NULL , toclass = "nested.datlist" ,
simplify = FALSE )
## S3 method for class 'nested.datlist'
subset(x, subset , select = NULL , expr_subset = NULL,
index_between = NULL, index_within = NULL, simplify=FALSE , ...)
## S3 method for class 'NestedImputationList'
subset(x, subset , select = NULL , expr_subset = NULL,
index_between = NULL, index_within = NULL, simplify=FALSE , ...)
|
datlist |
For |
subset |
Logical expression indicating elements or rows to keep, see
|
select |
Expression indicating columns to select from a data frame |
expr_subset |
Expression indicating a selection criterion for selection rows. |
index |
Vector of indices indicating which of the multiply imputed datasets should be selected. |
toclass |
The object class in which the datasets should be saved. |
index_between |
Index for between nest datasets |
index_within |
Index for within nest datasets |
simplify |
Optional logical indicating whether a nested multiply imputed dataset should be simplified to a multiplied imputed dataset. |
x |
Object containing multiply imputed or nested multiply imputed datasets |
... |
Further arguments to be passed. |
For multiply imputed datasets: Object of class datlist
,
imputationList
or mids
For nested multiply imputed datasets: Object of class
nested.datlist
or NestedImputationList
.
If subsetting is applied to objects of class mids
(or mids.1chain
),
then informations about the imputation procedure are lost.
Alexander Robitzsch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | #############################################################################
# EXAMPLE 1: Subsetting and selection of multiply imputed datasets
#############################################################################
data(data.ma02)
# define original list of datasets
datlist1a <- data.ma02
# object of class datlist
datlist1b <- miceadds::datlist_create(datlist1a)
datlist1b
# object of class imputationList
datlist1c <- mitools::imputationList(datlist1a)
datlist1c
# object of class mids
datlist1d <- miceadds::datlist2mids(datlist1a)
datlist1d
# select some imputed datasets
datlist2a <- miceadds::subset_datlist( datlist1a , index = c(5,3,7) )
datlist2a
# convert to class imputationList
datlist2b <- miceadds::subset_datlist( datlist1a , index = c(5,3,7),
toclass = "imputationList")
datlist2b
# convert to class mids
datlist2c <- miceadds::subset_datlist( datlist1a , index = 1:3 , toclass = "mids")
datlist2c
## Not run:
# select some variables
datlist3a <- miceadds::subset_datlist( datlist1a , select = c("idstud" , "books") )
datlist3a
# Because datlist1b is a datlist it is equivalent to
datlist3b <- subset( datlist1b , select = c("idstud" , "books") )
datlist3b
# operating on imputationList class
datlist3c <- miceadds::subset_datlist( datlist1c , select = c("idstud" , "books") )
datlist3c
# operating on mids class
datlist3d <- miceadds::subset_datlist( datlist1d , select = c("idstud" , "books") )
datlist3d
# selection of rows and columns in multiply imputed datasets
datlist4a <- miceadds::subset_datlist( datlist1a , index = 1:5 ,
subset = datlist1a[[1]]$idschool < 1067 ,
select = c("idstud" , "idschool","hisei") )
datlist4a
# convert to class mids
datlist4b <- miceadds::subset_datlist( datlist1a , index = 1:5 ,
subset = datlist1a[[1]]$idschool < 1067 ,
select = c("idstud" , "idschool","hisei") , toclass = "mids" )
datlist4b
# The same functionality, but now applying to object of class mids datlist1d
datlist4c <- subset( datlist1d , index = 1:5 , subset = datlist1a[[1]]$idschool < 1067,
select = c("idstud" , "idschool","hisei") )
datlist4c
# expression for selecting rows specific in each data frame
# which can result in differently sized datasets (because the variable
# migrant is imputed)
datlist5a <- miceadds::subset_datlist( datlist1a , expr_subset = migrant == 1 )
datlist5a
# select the first 100 cases
datlist6a <- miceadds::subset_datlist( datlist1a , select = c("idstud" , "books"),
subset=1:100 )
datlist6a
#############################################################################
# EXAMPLE 2: Subsetting and selection of nested multiply imputed datasets
#############################################################################
library(BIFIEsurvey)
data(data.timss4, package="BIFIEsurvey")
dat <- data.timss4
# create object of class 'nested.datlist'
datlist1a <- miceadds::nested.datlist_create( dat )
# create object of class 'NestedImputationList'
datlist1b <- miceadds::NestedImputationList(dat)
# create object of class 'mids.nmi'
datlist1c <- miceadds::datlist2mids(dat)
# select some between datasets
datlist2a <- subset_nested.datlist( datlist1a , index_between = c(1,3,4) )
datlist2a
# shorter version
datlist2b <- subset( datlist1a , index_between = c(1,3,4) )
datlist2b
# conversion of a NestedImputationList
datlist2c <- subset( datlist1b , index_between = c(1,3,4))
datlist2c
# select rows and columns
sel_cases <- datlist1a[[1]][[1]]$JKZONE <= 42
datlist3a <- subset( datlist1a , subset = sel_cases ,
select = c("IDSTUD","books", "ASMMAT") )
datlist3a
# remove within nest
datlist4a <- subset( datlist1a , index_within = 1 )
datlist4a
# remove within nest and simplify structure
datlist4b <- subset( datlist1a , index_within = 1 , simplify = TRUE)
datlist4b
datlist4c <- subset( datlist1b , index_within = 1 , simplify = TRUE)
datlist4c
# remove between nest
datlist5a <- subset( datlist1a , index_between = 1 , simplify = TRUE)
datlist5a
datlist5b <- subset( datlist1b , index_between = 1 , simplify = TRUE)
datlist5b
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.