yrosseel / lavaan

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

Error in standardizedSolution (with bootstrapped model), lavaan 6.0.1 #102

Closed jogrue closed 6 years ago

jogrue commented 6 years ago

Hello,

I think i found an issue with the new standardizedSolution function. The issue occurs when using it with a bootstrapped model. In that case, simple symetric CIs should be computed here:

https://github.com/yrosseel/lavaan/blob/master/R/lav_object_methods.R#L351

        if(object@Options$se != "bootstrap") {
            fac <- qnorm(a)
            ci <- LIST$est + LIST$se %o% fac
        } else {
            ci <- rep(as.numeric(NA), length(LIST$est)) + LIST$se %o% fac
        }

But if the standard errors are bootstrapped, "fac" is not defined and i get the following error:

Error in as.vector(x, mode) : 
  cannot coerce type 'closure' to vector of type 'any'

This example gives me the error (lavaan 6.0.1). I hope I did not miss anything.

library(lavaan)
packageVersion("lavaan")

y <- rnorm(1000, mean = 0, sd = 1)

x1 <- rnorm(1000, mean = 0, sd = 1)
x2 <- y * runif(1000, min = 0.3, max = 0.6)

moddata <- as.data.frame(cbind(y = y, x1 = x1, x2 = x2))
lm(y ~ x1 + x2)

modelsyntax <- "y =~ x1 + x2"
mod <- sem(model = modelsyntax,
           data = moddata,
           se = "bootstrap",
           bootstrap = 100)
summary(mod)
parameterEstimates(mod, standardized = TRUE)
standardizedSolution(mod)
yrosseel commented 6 years ago

Thanks. Fixed in dev 0.6-2.1278.

Yves.