philchalmers / mirt

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

draw_parameters() throwing error with SingleGroupClass fitted object #169

Closed ddueber closed 4 years ago

ddueber commented 5 years ago

The following code throws an error:

a <- matrix(rep(1, 20), ncol = 1)
d <- rnorm(20, 0, 1)
MyData <- simdata(a, d, 1000, itemtype = "2PL")
mod1 <- mirt(MyData, 1, SE= TRUE)
draw_parameters(mod1, 10)

The error is

Error in draw_parameters(mod1, 10) : 
  no slot of name "ParObjects" for this object of class "dich"

But when I make it multi-group data, everything is ok:

group <- c(rep("G1", 500), rep("G2", 500))
mod2 <- multipleGroup(MyData, 1, group = group, SE = TRUE, invariance = c("free_means", "free_var", "slopes", "intercepts"))
draw_parameters(mod2, 10)

I recognize that draw_parameters() is typically used with DRF, and therefore on MultiGroupClass objects. However, I am hoping to use Lee, Cai, & Kuhfeld's (2016) "poor person's posterior predictive checking" on SingleGroupClass objects.

philchalmers commented 5 years ago

Thanks, I was aware of the problem. Parts of the package related to graphical methods actually do this already, so the fix should be straightforward.

ddueber commented 5 years ago

Thanks for your quick attention. In the meantime, is there a way for me to create a fake MultiGroupClass object and feed the fitted SingleGroupClasss object into the appropriate slot(s)?

philchalmers commented 5 years ago

Interesting question. I suppose you could add in some dummy data to your original dataset, create a group variable to indicate the original and new response vectors, and fix all the parameters in the dummy data group at their starting values. Or, you could try and do the parameter generation manually by extracting the parameters and VCOV matrix directly yourself.

philchalmers commented 4 years ago

The above code now runs correctly with the dev version, so feel free to install for the fix. Thanks for the report!