simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

Bootstrap confidence intervals for htmt() function? #34

Closed chriscastille6 closed 6 years ago

chriscastille6 commented 6 years ago

Is there a way to obtain confidence intervals for the statistics produced by the htmt() function? I've asked around but have not had any luck.

TDJorgensen commented 6 years ago

Not that I am aware of, but you could email the contributor of this function (Ylenio Longo, his email is on the ?htmt help page). Your subject line says "bootstrap", which you could do using the boot package:

library(boot)
library(semTools)
dat <- HolzingerSwineford1939[, paste0("x", 1:9)]
f <- function(data, i) {
    library(semTools)
    HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 '
    out <- htmt(HS.model, data = data[i, ])
    out[lower.tri(out)] # extracts only the unique elements
}
boot.out <- boot(dat, statistic = f, R = 500, # should use a few thousand
                 parallel = "snow", ncpus = parallel::detectCores() - 1L)
boot.out # compare to htmt() output to see which index is which correlation
boot.ci(boot.out, index = 1)
boot.ci(boot.out, index = 2)
boot.ci(boot.out, index = 3)