BIFIE.BIFIEdata2BIFIEcdata: Conversion and Selection of 'BIFIEdata' Objects

View source: R/BIFIE.bifiedata2bifiecdata.R

BIFIE.BIFIEdata2BIFIEcdataR Documentation

Conversion and Selection of BIFIEdata Objects

Description

Functions for converting and selecting objects of class BIFIEdata. The function BIFIE.BIFIEdata2BIFIEcdata converts the BIFIEdata objects in a non-compact form (cdata=FALSE) into an object of class BIFIEdata in a compact form (cdata=TRUE). The function BIFIE.BIFIE2data2BIFIEdata takes the reverse operation.

The function BIFIE.BIFIEdata2datalist converts a (part) of the object of class BIFIEdata into a list of multiply-imputed datasets.

Usage

BIFIE.BIFIEdata2BIFIEcdata(bifieobj, varnames=NULL, impdata.index=NULL)

BIFIE.BIFIEcdata2BIFIEdata(bifieobj, varnames=NULL, impdata.index=NULL)

BIFIE.BIFIEdata2datalist(bifieobj, varnames=NULL, impdata.index=NULL,
    as_data_frame=FALSE)

Arguments

bifieobj

Object of class BIFIEdata

varnames

Variables chosen for the selection

impdata.index

Selected indices of imputed datasets

as_data_frame

Logical indicating whether list of length one should be converted into a data frame

Value

An object of class BIFIEdata saved in a non-compact or compact way, see value cdata.

See Also

BIFIE.data

Examples

#############################################################################
# EXAMPLE 1: BIFIEdata conversions using data.timss1 dataset
#############################################################################
data(data.timss1)
data(data.timssrep)

# create BIFIEdata object
bdat1 <- BIFIEsurvey::BIFIE.data( data.list=data.timss1, wgt=data.timss1[[1]]$TOTWGT,
            wgtrep=data.timssrep[, -1 ])
summary(bdat1)

# convert BIFIEdata object bdat1 into a BIFIEcdata object with
#  only using the first three datasets and a variable selection
bdat2 <- BIFIEsurvey::BIFIE.BIFIEdata2BIFIEcdata( bifieobj=bdat1,
                varnames=bdat1$varnames[ c(1:7,10) ] )

# convert bdat2 into BIFIEdata object and only use the first three imputed datasets
bdat3 <- BIFIEsurvey::BIFIE.BIFIEcdata2BIFIEdata( bifieobj=bdat2, impdata.index=1:3)

# object summaries
summary(bdat1)
summary(bdat2)
summary(bdat3)

## Not run: 
#############################################################################
# EXAMPLE 2: Extract unique elements in BIFIEdata object
#############################################################################

data(data.timss1)
data(data.timssrep)

# create BIFIEdata object
bifieobj <- BIFIEsurvey::BIFIE.data( data.list=data.timss1, wgt=data.timss1[[1]]$TOTWGT,
            wgtrep=data.timssrep[, -1 ])
summary(bifieobj)

# define variables for which unique values should be extracted
vars <- c( "female", "books","ASMMAT" )
# convert these variables from BIFIEdata object into a list of datasets
bdatlist <- BIFIEsurvey::BIFIE.BIFIEdata2datalist( bifieobj, varnames=vars )
# look for unique values in first dataset for variables
values <- lapply( bdatlist[[1]], FUN=function(vv){
                sort( unique( vv ) ) } )
# number of unique values in first dataset
Nvalues <- lapply( bdatlist[[1]], FUN=function(vv){
                length( unique( vv ) ) } )
# number of unique values in all datasets
Nvalues2 <- lapply( vars, FUN=function(vv){
    #vv <- vars[1]
    unlist( lapply( bdatlist, FUN=function(dd){
                length( unique( dd[,vv]  ) )
                        }    )     )
                    } )
# --> for extracting the number of unique values using BIFIE.by and a user
#     defined function see Example 1, Model 3 in "BIFIE.by"

## End(Not run)

BIFIEsurvey documentation built on May 29, 2024, 2:52 a.m.