Learn R Programming

sem (version 3.1-16)

bootSem: Bootstrap a Structural Equation Model

Description

Bootstraps a structural equation model in an sem object (as returned by the sem function).

Usage

bootSem(model, ...)

# S3 method for sem bootSem(model, R=100, Cov=cov, data=model$data, max.failures=10, show.progress=TRUE, ...)

# S3 method for msem bootSem(model, R=100, Cov=cov, data=model$data, max.failures=10, show.progress=TRUE, ...)

# S3 method for bootsem print(x, digits=getOption("digits"), ...)

# S3 method for bootsem summary(object, type=c("perc", "bca", "norm", "basic", "none"), level=0.95, ...)

Value

bootSem returns an object of class bootsem, which inherits from class boot, supported by the boot package. The returned object contains the following components:

t0

the estimated parameters in the model fit to the original data set.

t

a matrix containing the bootstrapped estimates, one bootstrap replication per row.

data

the data to which the model was fit.

seed

the value of .Random.seed when bootSem was called.

statistic

the function used to produce the bootstrap replications; this is always the local function refit from bootSem.

sim

always set to "ordinary"; see the documentation for the boot function.

stype

always set to "i"; see the documentation for the boot function.

call

the call of the bootSem function.

weights

a vector of length equal to the number of observations \(N\), with entries \(1/N\). For a multi-group model, the weights in group \(j\) are \(1/N_j\), the inverse of the number of observations in the group.

strata

a vector of length \(N\) containing the number of the stratum to which each observation belongs; for a single-group model, all entries are 1.

Arguments

model

an sem or msem object, produced by the sem function.

R

the number of bootstrap replications; the default is 100, which should be enough for computing standard errors, but not confidence intervals (except for the normal-theory intervals).

Cov

a function to compute the input covariance or moment matrix; the default is cov. Use cor if the model is fit to the correlation matrix. The function hetcor in the polycor package will compute product-moment, polychoric, and polyserial correlations among mixed continuous and ordinal variables (see the first example below for an illustration).

data

in the case of a sem (i.e., single-group) model, a data set in a form suitable for Cov; for example, for the default Cov=cov, data may be a numeric data frame or a numeric matrix. In the case of an msem (i.e., multi-group) model, a list of data sets (again in the appropriate form), one for each group; in this case, bootstrapping is done within each group, treating the groups as strata. Note that the original observations are required, not just the covariance matrix of the observed variables in the model. The default is the data set stored in the sem object, which will be present only if the model was fit to a data set rather than to a covariance or moment matrix, and may not be in a form suitable for Cov.

max.failures

maximum number of consecutive convergence failures before bootSem gives up.

show.progress

display a text progress bar on the console tracing the bootstrap replications.

x, object

an object of class bootsem.

digits

controls the number of digits to print.

type

type of bootstrapped confidence intervals to compute; the default is "perc" (percentile); see boot.ci for details.

level

level for confidence intervals; default is 0.95.

...

in bootSem, arguments to be passed to sem; otherwise ignored.

Author

John Fox jfox@mcmaster.ca

Details

bootSem implements the nonparametric bootstrap, assuming an independent random sample. Convergence failures in the bootstrap resamples are discarded (and a warning printed); more than max.failures consecutive convergence failures (default, 10) result in an error. You can use the boot function in the boot package for more complex sampling schemes and additional options.

Bootstrapping is implemented by resampling the observations in data, recalculating the input covariance matrix with Cov, and refitting the model with sem, using the parameter estimates from the original sample as start-values.

Warning: the bootstrapping process can be very time-consuming.

References

Davison, A. C., and Hinkley, D. V. (1997) Bootstrap Methods and their Application. Cambridge.

Efron, B., and Tibshirani, R. J. (1993) An Introduction to the Bootstrap. Chapman and Hall.

See Also

boot, sem

Examples

Run this code
    if (FALSE)  # because of long execution time

# A simple confirmatory factor-analysis model using polychoric correlations.
#  The polycor package is required for the hetcor function.

if (require(polycor)){

# The following function returns correlations computed by hetcor,
#   and is used for the bootstrapping.

hcor <- function(data) hetcor(data, std.err=FALSE)$correlations

model.cnes <- specifyModel(text="
F -> MBSA2, lam1
F -> MBSA7, lam2
F -> MBSA8, lam3
F -> MBSA9, lam4
F <-> F, NA, 1
MBSA2 <-> MBSA2, the1
MBSA7 <-> MBSA7, the2
MBSA8 <-> MBSA8, the3
MBSA9 <-> MBSA9, the4
")

R.cnes <- hcor(CNES)

sem.cnes <- sem(model.cnes, R.cnes, N=1529)
summary(sem.cnes)
}

#  Note: this can take a minute:

set.seed(12345) # for reproducibility

system.time(boot.cnes <- bootSem(sem.cnes, R=100, Cov=hcor, data=CNES))
summary(boot.cnes, type="norm")  
# cf., standard errors to those computed by summary(sem.cnes)
    
    
    if (FALSE)   # because of long execution time

# An example bootstrapping a multi-group model

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")) 

sem.mg <- sem(mod.mg, data=HS.data, group="Gender",
              formula = ~ visual + cubes + paper + flags +
              general + paragrap + sentence + wordc + wordm +
              wordr + numberr + figurer + object + numberf + figurew +
              deduct + numeric + problemr + series + arithmet
              )

# Note: this example can take several minutes or more;
#       you can decrease R if you just want to see how it works:

set.seed(12345) # for reproducibility

system.time(boot.mg <- bootSem(sem.mg, R=100))
summary(boot.mg, type="norm")
# cf., standard errors to those computed by summary(sem.mg)
    

Run the code above in your browser using DataLab