BIFIE.lavaan.survey {BIFIEsurvey}R Documentation

Fitting a Model in lavaan or in survey

Description

The function BIFIE.lavaan.survey fits a structural equation model in lavaan using the lavaan.survey package. Currently, only maximum likelihood estimation for normally distributed data is available.

The function BIFIE.survey fits a model defined in the survey package.

Usage

BIFIE.lavaan.survey(lavmodel, svyrepdes, lavaan_fun="sem",
    lavaan_survey_default=FALSE, fit.measures=NULL, ...)

## S3 method for class 'BIFIE.lavaan.survey'
summary(object, ...)

## S3 method for class 'BIFIE.lavaan.survey'
coef(object,...)

## S3 method for class 'BIFIE.lavaan.survey'
vcov(object,...)

BIFIE.survey(svyrepdes, survey.function, ...)

## S3 method for class 'BIFIE.survey'
summary(object, digits=3, ...)

## S3 method for class 'BIFIE.survey'
coef(object,...)

## S3 method for class 'BIFIE.survey'
vcov(object,...)

Arguments

lavmodel

Model string in lavaan syntax

svyrepdes

Replication design object of class BIFIEdata or replication design object from survey package (generated by BIFIEdata2svrepdesign or survey::svrepdesign)

lavaan_fun

Estimation funcion in lavaan. Can be "lavaan", "sem", "cfa" or "growth".

lavaan_survey_default

Logical indicating whether the lavaan.survey package should be used for statistical inference for multiply imputed datasets.

object

Object of class BIFIE.by

fit.measures

Optional vector of fit measures used in lavaan::fitMeasures function

...

Further arguments to be passed

survey.function

Function from the survey package

digits

Number of digits after decimal

Value

For BIFIE.lavaan.survey a list with following entries

lavfit

Object of class lavaan

fitstat

Fit statistics from lavaan

See Also

lavaan::lavaan, lavaan.survey::lavaan.survey

Examples

## Not run: 
#############################################################################
# EXAMPLE 1: Multiply imputed datasets, TIMSS replication design
#############################################################################

library(lavaan)
data(data.timss2)
data(data.timssrep)

#--- create BIFIEdata object
bdat4 <- BIFIEsurvey::BIFIE.data( data=data.timss2, wgt="TOTWGT",
                wgtrep=data.timssrep[,-1], fayfac=1)
print(bdat4)

#--- create survey object with conversion function
svydes4 <- BIFIEsurvey::BIFIEdata2svrepdesign(bdat4)

#*** regression model
mod1 <- BIFIEsurvey::BIFIE.linreg(bdat4, formula=ASMMAT ~ ASSSCI )
mod2 <- mitools::MIcombine( with(svydes4, survey::svyglm( formula=ASMMAT ~ ASSSCI,
                       design=svydes4 )))
#--- regression with lavaan.survey package
lavmodel <- "ASMMAT ~ 1
             ASMMAT ~ ASSSCI"
mod3 <- BIFIEsurvey::BIFIE.lavaan.survey(lavmodel, svyrepdes=svydes4)
# inference included in lavaan.survey package
mod4 <- BIFIEsurvey::BIFIE.lavaan.survey(lavmodel, svyrepdes=svydes4,
                        lavaan_survey_default=TRUE)
summary(mod3)
# extract fit statistics
lavaan::fitMeasures(mod3$lavfit)

#--- use BIFIE.lavaan.survey function with BIFIEdata object
mod5 <- BIFIEsurvey::BIFIE.lavaan.survey(lavmodel, svyrepdes=bdat4)
summary(mod5)

# compare estimated parameters
coef(mod1); coef(mod2); coef(mod3); coef(mod4); coef(mod5)

# compare standard error estimates
se(mod1); BIFIEsurvey::se(mod2); BIFIEsurvey::se(mod3); BIFIEsurvey::se(mod4); BIFIEsurvey::se(mod5)

#############################################################################
# EXAMPLE 2: Examples BIFIE.survey function
#############################################################################

data(data.timss2)
data(data.timssrep)

#--- create BIFIEdata object
bdat <- BIFIEsurvey::BIFIE.data( data=data.timss2, wgt="TOTWGT",
              wgtrep=data.timssrep[,-1], fayfac=1)
print(bdat)

#--- survey object
sdat <- BIFIEsurvey::BIFIEdata2svrepdesign(bdat)
print(sdat)

#- fit models in survey
mod1 <- BIFIEsurvey::BIFIE.linreg(bdat, formula=ASMMAT~ASSSCI)
mod2 <- BIFIEsurvey::BIFIE.survey( sdat, survey.function=survey::svyglm,
                                    formula=ASMMAT~ASSSCI)
mod3 <- BIFIEsurvey::BIFIE.survey( bdat, survey.function=survey::svyglm,
                                     formula=ASMMAT~ASSSCI)
summary(mod1)
summary(mod2)
summary(mod3)

#############################################################################
# EXAMPLE 3: Nested multiply imputed datasets | linear regression
#############################################################################

library(lavaan)
data(data.timss4)
data(data.timssrep)

# nested imputed dataset
bdat <- BIFIEsurvey::BIFIE.data( data.list=data.timss4,
            wgt=data.timss4[[1]][[1]]$TOTWGT, wgtrep=data.timssrep[, -1 ],  NMI=TRUE )
summary(bdat)

#*** BIFIEsurvey::BIFIE.linreg
mod1 <- BIFIEsurvey::BIFIE.linreg(bdat, formula=ASMMAT ~ migrant )

#*** survey::svyglm
mod2 <- BIFIEsurvey::BIFIE.survey(bdat, survey.function=survey::svyglm,
                                    formula=ASMMAT~migrant)

#*** lavaan.survey::lavaan.survey
lavmodel <- "ASMMAT ~ 1
             ASMMAT ~ migrant"
mod3 <- BIFIEsurvey::BIFIE.lavaan.survey(lavmodel, svyrepdes=bdat)

coef(mod1); coef(mod2); coef(mod3)
se(mod1); BIFIEsurvey::se(mod2), BIFIEsurvey::se(mod3)

## End(Not run)

[Package BIFIEsurvey version 3.3-12 Index]