yrosseel / lavaan

an R package for structural equation modeling and more
http://lavaan.org
412 stars 99 forks source link

Bootstrap bug when estimator = MLR and missing = direct #275

Closed LukasWallrich closed 1 year ago

LukasWallrich commented 1 year ago

I was rerunning some old code that used to work (up to version 0.6.12), but now fails (from 0.6.13). It estimates a mediation model and then bootstraps confidence intervals – but with estimator = MLR and missing = direct, that fails with an Error in colSums … see below. Note that this is not dependent on mtcars – I get the same with rnorm data etc. Note that this works when the estimator is ML or missing not set.

With lavaan from 0.6-13 (including current CRAN version)

library(groundhog)
#> Attached: 'Groundhog' (Version: 3.0.0)
#> Tips and troubleshooting: https://groundhogR.com
groundhog.library("lavaan", "2023-01-31", tolerate.R.version='4.3.0')
#> This is lavaan 0.6-13
#> lavaan is FREE software! Please report any bugs.
#> Successfully attached 'lavaan_0.6-13'

df <- data.frame(X = mtcars$wt, M1 = mtcars$cyl, M2 = mtcars$am, Y = mtcars$mpg)

mod <- "    #Mediators     
M1 ~ a*X  
M2 ~ b*X 
 #Outcome
Y ~ cdash*X + aa*M1 + bb*M2"

# Fails
fit <- lavaan::sem(mod, df, estimator = "MLR", 
                   missing = "direct")

out <- lavaan::bootstrapLavaan(fit, R = 10)
#> Error in colSums(S): 'x' must be an array of at least two dimensions

Up until lavaan 0.6-12, it works.

yrosseel commented 1 year ago

Thanks! This is now fixed in the github version.