@@ -323,11 +323,9 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ..
323323 .quitAnalysis(gettext(" Bootstrapping is not available for variance-covariance matrix input." ))
324324 }
325325
326- # cfaResult[["lav"]] <- jaspSem::lavBootstrap(cfaResult[["lav"]], options$bootstrapSamples,
327- # standard = options[["standardized"]] != "none", typeStd = type)
326+ cfaResult [[" lav" ]] <- jaspSem :: lavBootstrap(cfaResult [[" lav" ]], options $ bootstrapSamples ,
327+ standard = options [[" standardized" ]] != " none" , typeStd = type )
328328
329- cfaResult [[" lav" ]] <- lavBootstrap(cfaResult [[" lav" ]], options $ bootstrapSamples ,
330- standard = options [[" standardized" ]] != " none" , typeStd = type )
331329 }
332330
333331 # Save cfaResult as state so it's available even when opts don't change
@@ -1534,67 +1532,6 @@ confirmatoryFactorAnalysisInternal <- function(jaspResults, dataset, options, ..
15341532
15351533}
15361534
1537- # delete this once jaspSem is merged
1538- lavBootstrap <- function (fit , samples = 1000 , standard = FALSE , typeStd = NULL , iseed = NULL ) {
1539-
1540- coefWithCallback <- function (lav_object ) {
1541- # Progress bar is ticked every time coef() is evaluated, which happens once on the main object:
1542- # https://github.com/yrosseel/lavaan/blob/77a568a574e4113245e2f6aff1d7c3120a26dd90/R/lav_bootstrap.R#L107
1543- # and then every time on a successful bootstrap:
1544- # https://github.com/yrosseel/lavaan/blob/77a568a574e4113245e2f6aff1d7c3120a26dd90/R/lav_bootstrap.R#L375
1545- # i.e., samples + 1 times
1546- progressbarTick()
1547- return (lavaan :: coef(lav_object ))
1548- }
1549-
1550- coefWithCallbackStd <- function (lav_object , typeStd ) {
1551- std <- lavaan :: standardizedSolution(lav_object , type = typeStd )
1552- out <- std $ est.std
1553-
1554- progressbarTick()
1555-
1556- return (out )
1557- }
1558-
1559- startProgressbar(samples + 1 )
1560-
1561- if (! standard ) {
1562- bootres <- lavaan :: bootstrapLavaan(object = fit , R = samples , FUN = coefWithCallback , iseed = iseed )
1563- } else {
1564- bootres <- lavaan :: bootstrapLavaan(object = fit , R = samples , FUN = coefWithCallbackStd , typeStd = typeStd , iseed = iseed )
1565- }
1566-
1567- # Add the bootstrap samples to the fit object
1568- fit @ boot <- list (coef = bootres )
1569- fit @ Options $ se <- " bootstrap"
1570-
1571- # exclude error bootstrap runs
1572- errId <- attr(fit @ boot $ coef , " error.idx" )
1573- if (length(errId ) > 0L ) {
1574- fit @ boot $ coef <- fit @ boot $ coef [- errId , , drop = FALSE ]
1575- }
1576-
1577- # we actually need the SEs from the bootstrap not the SEs from ML or some other estimator
1578- N <- nrow(fit @ boot $ coef )
1579- P <- ncol(fit @ boot $ coef )
1580- freePars <- which(fit @ ParTable $ free != 0 )
1581-
1582- # we multiply the var by (n-1)/n because lavaan actually uses n for the variance instead of n-1
1583- if (! standard ) {
1584- # for unstandardized
1585- fit @ ParTable $ se [freePars ] <- apply(fit @ boot $ coef , 2 , sd ) * sqrt((N - 1 )/ N )
1586- } else {
1587- # when there are contraints the parameterestimates() function expects a boot sample for the free parameters only
1588- fit @ ParTable $ se [1 : P ] <- apply(fit @ boot $ coef , 2 , sd ) * sqrt((N - 1 )/ N )
1589- fit @ boot $ coef <- fit @ boot $ coef [, freePars , drop = FALSE ]
1590- std <- lavaan :: standardizedSolution(fit , type = typeStd )
1591- # for the standardized output we also replace some constrained elements
1592- fit @ ParTable $ est [1 : P ] <- std $ est.std
1593- }
1594-
1595- return (fit )
1596- }
1597-
15981535
15991536.cfaAddScoresToData <- function (jaspResults , options , cfaResult , dataset ) {
16001537
0 commit comments