philchalmers / mirt

Multidimensional item response theory
https://philchalmers.github.io/mirt/
201 stars 75 forks source link

Error in fscores #207

Closed LoneyC closed 3 years ago

LoneyC commented 3 years ago

Hi Phil, when using the fscores command I get the following error message:

Error in if (nc == 0) { : Missing value, where TRUE/FALSE is needed.

For context this is the code I'm using and there are no issues with the mirt or coef command.

model<- mirt.model('theta = 1-10 ERS = 11-20 COV=theta*ERS') IRTree<- mirt(data, model, itemtype='Rasch', SE=TRUE) coef<- coef(IRTree, simplify=TRUE) estimated.theta <- fscores(IRTree, method = "EAP", full.scores = TRUE)

I think the issue is very similar to the inversion bug from a couple days ago and hopefully it will be easy to fix.

philchalmers commented 3 years ago

It seems the only way I can reproduce this issue is when the model itself has converged to an improper solution (e.g., when the latent trait covariance matrix is non-positive definite). I'll make a better check for this where applicable in the package to make this error a bit smoother. Below is the new behaviour. Thanks for the report!

library(mirt)
head(SAT12)
data <- key2binary(SAT12,
                   key = c(1,4,5,2,3,1,2,1,3,1,2,4,2,1,5,3,4,4,1,4,3,3,4,1,3,5,1,3,1,5,4,5))
data <- data[,1:20]

model<- mirt.model('theta = 1-10
ERS = 11-20
COV=theta*ERS')
IRTree<- mirt(data, model, itemtype='Rasch', SE=TRUE)
coef<- coef(IRTree, simplify=TRUE)
estimated.theta <- fscores(IRTree, method = "EAP", full.scores = TRUE)

>  Error: sigma matrix contains negative eigenvalues