miSem: Estimate a Structural Equation Model By Multiple Imputation

View source: R/miSem.R

miSemR Documentation

Estimate a Structural Equation Model By Multiple Imputation

Description

miSem uses the mi function in the mi package to generate multiple imputations of missing data, fitting the specified model to each completed data set.

Usage

miSem(model, ...)

## S3 method for class 'semmod'
miSem(model, ..., data, formula = ~., raw=FALSE, 
        fixed.x=NULL, objective=objectiveML,
        n.imp=5, n.chains=n.imp, n.iter=30, seed=sample(1e6, 1), mi.args=list(), 
        show.progress=TRUE)
    
## S3 method for class 'semmodList'
miSem(model, ..., data, formula = ~., group, raw=FALSE, 
        fixed.x=NULL, objective=msemObjectiveML,
        n.imp=5, n.chains=n.imp, n.iter=30, seed=sample(1e6, 1), mi.args=list(),
        show.progress=TRUE)

## S3 method for class 'miSem'
print(x, ...)

## S3 method for class 'miSem'
summary(object, digits=max(3, getOption("digits") - 2), ...)

Arguments

model

an SEM model-description object of class semmod or semmodList, created by specifyEquations cfa, or specifyModel, in the case of a multi-group model in combination with multigroupModel.

..., formula, raw, fixed.x, objective, group

arguments to be passed to sem.

data

an R data frame, presumably with some missing data (encoded as NA), containing the data for fitting the SEM, possibly along with other variables to use to obtain multiple imputations of missing values. In the case of a multi-group model, this must be a single data frame.

n.imp

number of imputations (default 5).

n.chains

number of Markov chains (default is the number of imputations).

n.iter

number of iterations for the multiple-imputation process (default 30).

seed

seed for the random-number generator (default is an integer sampled from 1 to 1E6); stored in the resulting object.

mi.args

other arguments to be passed to mi.

show.progress

show a text progress bar on the console tracking model fitting to the multiple imputations; this is distinct from the progress of the multiple-imputation process, which is controlled by the verbose argument to mi (and which, although it defaults to TRUE, fails to produce verbose output on Windows system, as of mi version 1.0).

x, object

an object of class "miSem".

digits

for printing numbers.

Value

miSem returns an object of class "miSem" with the following components:

initial.fit

an sem model object produced using objectiveFIML if raw=TRUE, or the objective function given by the objective argument otherwise.

mi.fits

a list of sem model objects, one for each imputed data set.

imputation

the object produced by complete, containing the completed imputed data sets.

seed

the seed used for the random number generator.

mi.data

the object returned by mi, containing the multiple imputations, and useful, e.g., for diagnostic checking of the imputation process.

Author(s)

John Fox jfox@mcmaster.ca

References

Yu-Sung Su, Andrew Gelman, Jennifer Hill, Masanao Yajima. (2011). “Multiple imputation with diagnostics (mi) in R: Opening windows into the black box.” Journal of Statistical Software 45(2).

See Also

sem, mi

Examples

    ## Not run:  # because of long execution time
mod.cfa.tests <- cfa(raw=TRUE, text="
verbal: x1, x2, x3
math: y1, y2, y3
")
imps <- miSem(mod.cfa.tests, data=Tests, fixed.x="Intercept", 
              raw=TRUE, seed=12345)
summary(imps, digits=3) 


# introduce some missing data to the HS.data data set:
HS <- HS.data[, c(2,7:10,11:15,20:25,26:30)]
set.seed(12345)
r <- sample(301, 100, replace=TRUE)
c <- sample(2:21, 100, replace=TRUE)
for (i in 1:100) HS[r[i], c[i]] <- NA

mod.hs <- cfa(text="
spatial: visual, cubes, paper, flags
verbal: general, paragrap, sentence, wordc, wordm
memory: wordr, numberr, figurer, object, numberf, figurew
math: deduct, numeric, problemr, series, arithmet
")

mod.mg <- multigroupModel(mod.hs, groups=c("Female", "Male")) 
system.time( # relatively time-consuming!
  imps.mg <- miSem(mod.mg, data=HS, group="Gender", seed=12345)
)
summary(imps.mg, digits=3)
    
## End(Not run)

sem documentation built on April 11, 2022, 1:06 a.m.

Related to miSem in sem...