My goal is to generate a list of dataframes from a lavaan
model using simsem::sim
. Depending on if the dataOnly
argument is TRUE or FALSE, simsem::sim
will either generate a SimResult
object (which includes generated data plus parameter values, fit indices, etc.) or just a list of the generated dataframes.
If I impose any missingness on the generated dataframes, I am incapable of generating the full SimResult
object. I can either generate a SimResult
object with no missingness or I can generate a list of dataframes with missingness. Trying to generate the SimResult
object with missingness gives the below error message, but I couldn't find any argument for sem
, simsem::miss
, or simsem::sim
where I could specify to use the D2 pooling method. Any help would be appreciated.
#> Error in D3.LRT(object, h1 = h1, useImps = useImps, asymptotic = asymptotic, : D3 test statistic could not be calculated. Try the D2 pooling method.
set.seed(123)
suppressMessages(library(mice))
suppressMessages(library(lavaan))
suppressMessages(library(simsem))
data(mtcars)
model <- 'gear ~ carb'
fit <- lavaan::sem(model, data = mtcars)
make_missing <- simsem::miss(package = "mice", m = 2, maxit = 2, seed = 123)
thisworks <- simsem::sim(
nRep = 10,
model = fit,
n = 5)
#> Progress: 1 / 10
#> Progress: 2 / 10
#> Progress: 3 / 10
#> Progress: 4 / 10
#> Progress: 5 / 10
#> Progress: 6 / 10
#> Progress: 7 / 10
#> Progress: 8 / 10
#> Progress: 9 / 10
#> Progress: 10 / 10
class(thisworks)
#> [1] "SimResult"
#> attr(,"package")
#> [1] "simsem"
thisdoesnotwork <- simsem::sim(
nRep = 10,
model = fit,
n = 5,
miss = make_missing)
#> Progress: 1 / 10
#> Error in D3.LRT(object, h1 = h1, useImps = useImps, asymptotic = asymptotic, : D3 test statistic could not be calculated. Try the D2 pooling method.
thispartiallyworks <- simsem::sim(
nRep = 10,
model = fit,
n = 5,
dataOnly = TRUE,
miss = make_missing)
#> Progress: 1 / 10
#> Progress: 2 / 10
#> Progress: 3 / 10
#> Progress: 4 / 10
#> Progress: 5 / 10
#> Progress: 6 / 10
#> Progress: 7 / 10
#> Progress: 8 / 10
#> Progress: 9 / 10
#> Progress: 10 / 10
class(thispartiallyworks)
#> [1] "list"