Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lavaan2mirt unexpectedly estimates a covariance matrix #16

Open
simonfelding opened this issue Apr 12, 2021 · 0 comments
Open

lavaan2mirt unexpectedly estimates a covariance matrix #16

simonfelding opened this issue Apr 12, 2021 · 0 comments

Comments

@simonfelding
Copy link

simonfelding commented Apr 12, 2021

Could you add an option to stop lavaan2mirt from estimating a covariance matrix when one is not specified in the lavaan model?

It seems like an odd default and it caused problems for me, exemplified by this cryptic error:

> lavaan2mirt(data, lavaan_model, poly.itemtype="graded", est.mirt=TRUE)
Error in chol.default(gp$gcov) : 
  the leading minor of order 1 is not positive definite

where lavaan_model is simply

[1] "# Latent variables\nML2 =~ dss_3 + dss_10 + dss_11 + dss_12 + dss_13 + dss_15 + dss_16 + dss_18 + dss_19 + dss_20\nML4 =~ dss_4 + dss_6 + dss_7 + dss_14 + dss_17\nML3 =~ dss_1 + dss_2 + dss_8 + dss_9\nML1 =~ dss_5"

The $mirt.syntax with est.mirt=FALSE is

> lavaan2mirt(data, lavaan_model %>% gsub("_", "", .), est.mirt=FALSE)$mirt.syntax
$x
     Type  Parameters                       
[1,] "ML2" "1,2,3,4,5,6,7,8,9,10"           
[2,] "ML4" "11,12,13,14,15"                 
[3,] "ML3" "16,17,18,19"                    
[4,] "ML1" "20"                             
[5,] "COV" "ML2*ML2,ML4*ML4,ML3*ML3,ML1*ML1"

I added the %>% gsub("_", "", .) to both the model and the dataset because I get Error in TAM::lavaanify.IRT(lavmodel, data = dat) : Please do not use _ in variable names in tamaan() function! without it.

Now that I look at it, it also seems odd that ML3 for example is [3,] "ML3" "16,17,18,19", when it is ML3 =~ dss_1 + dss_2 + dss_8 + dss_9 in lavaan form. The dataset has them ordered from col 1 to 20, so I would expect it to be [3,] "ML3" "1,2,8,9". Wouldn't it be easier to just the variable names since mirt.model accepts this? Then itemnames= could be passed as an argument too.

If it's any use, I generated the above lavaan model using psych::efa_to_cfa()

Thanks for the great and otherwise very useful package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants