Bootstrapping for the bias-corrected percentile method factor loading confidence intervals

1,275 views
Skip to first unread message

Jing Yu

unread,
Mar 22, 2016, 3:39:23 AM3/22/16
to lavaan
Hi Lavaan group,
I am trying to use the Lavaan to do the bootstrapping for the bias-corrected of the factor loading confidence intervals, and I have this code for the estimated standardized loadings below, but I can not figure out how to write the code for the bias-corrected factor loading confidence intervals. Does someone give me some suggestions? I appreciate your help. Thanks
out <- bootstrapLavaan(fit, R = 100, FUN = function(x) { 
standardizedSolution(x)$est }, verbose = TRUE) 





Terrence Jorgensen

unread,
Mar 22, 2016, 8:53:55 AM3/22/16
to lavaan
The bootstrapLavaan() function only returns the bootstrap distribution of the statistic(s), so I don't think you can get the bias-corrected CI this way.  You can get it using the boot function (from the boot package that comes with R by default).  For example:

## Define a function that fits a model to your data and returns the
## Std. estimates. The boot function requires the first argument to
## be the data.frame, and the second argument to be an index to
## select rows (i.e., to do bootstrap sampling)
getSTDs <- function(data, rowIndices) {
  library(lavaan)
  mySyntax <- ' visual  =~ x1 + x2 + x3
                textual =~ x4 + x5 + x6
                speed   =~ x7 + x8 + x9 '
  fit <- cfa(mySyntax, data = data[rowIndices, ] )
  standardizedSolution(fit)$est
}

## run bootstrap
out.boot <- boot(data = HolzingerSwineford1939, statistic = getSTDs, R = 2000)

## get bias-corrected CI, for one parameter (index) at a time
boot.ci(out.boot, type = "bca", index = 1)

## note the index corresponds to the actual order in which
## the parameters appear in the output:
example(cfa)
standardizedSolution(fit)

## You can request a set of BCa CIs
lapply(1:3, function(x) boot.ci(out.boot, type = "bca", index = x))

You need a lot more than 100 bootstrap samples to get a stable bias-corrected CI -- try 2000-5000.  You can use boot's built-in parallel options to make it go faster:

out.boot <- boot(data = HolzingerSwineford1939, statistic = getSTDs, R = 2000,
                 parallel = "snow", ncpus = parallel::detectCores() - 1)


If you just want bias-corrected CIs for raw parameters, you can get those using the arguments in the lavaan() and parameterEstimates() functions

fit <- lavaan(mySyntax, myData, ..., bootstrap = 1000L)
parameterEstimates(fit, boot.ci.type = "bca.simple")

Terry

Jing Yu

unread,
Mar 23, 2016, 8:24:31 PM3/23/16
to lav...@googlegroups.com
Hi Terry,
Thank you for your careful description of the syntax. I would like to try it as you suggested.

Many thanks,
Jing

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages