philchalmers / mirt

Multidimensional item response theory
199 stars 75 forks source link

Problem with simdata with itemtype = "graded" when item has 2 categories #248

Closed piotrkoc closed 5 months ago

piotrkoc commented 5 months ago

Hi,

I was simulating some data with itemtype = "graded" for 10 items that had a varying number of categories (2-20). I noticed that the function produced an unexpected output for the binary item. Now I realize that I should have useditemtype = ifelse(ic > 2, 'graded', '2PL') (where ic is a vector with the number of categories), but there was no warning message indicating that I cannot use itemtype = "graded" for an item with only 2 categories.

Maybe you could add such a message?

philchalmers commented 5 months ago

This behaviour was unintentional as the GRM with K=2 is just the 2PL model, so should have behaved as a such. I've made a patch to avoid this issue, so your original simulation code should now run correctly. Here's a demonstration with the example code in the package:

library(mirt)
### Unidimensional graded response model with 5 categories each
a <- matrix(rlnorm(5,.2,.3))

diffs <- t(apply(matrix(runif(5*1, .3, 1), 5), 1, cumsum))
diffs <- -(diffs - rowMeans(diffs))
d <- t(diffs + rnorm(5))
theta <- rnorm(100)

list(a=a, d=d)
$a
          [,1]
[1,] 1.2315119
[2,] 0.7378204
[3,] 1.6755228
[4,] 0.8729476
[5,] 1.3507840

$d
            [,1]
[1,] -0.59441687
[2,]  1.25472953
[3,] -0.20872976
[4,] -0.08601353
[5,] -0.02281470

set.seed(1)
dat.a <- simdata(a, d, itemtype = 'graded', Theta = theta)

set.seed(1)
dat.b <- simdata(a, d, itemtype = '2PL', Theta=theta)

head(dat.a) 
     Item_1 Item_2 Item_3 Item_4 Item_5
[1,]      0      1      0      1      1
[2,]      0      0      0      0      0
[3,]      1      0      1      1      1
[4,]      1      1      0      1      1
[5,]      0      0      0      1      1
[6,]      1      0      0      1      1

head(dat.b)
     Item_1 Item_2 Item_3 Item_4 Item_5
[1,]      0      1      0      1      1
[2,]      0      0      0      0      0
[3,]      1      0      1      1      1
[4,]      1      1      0      1      1
[5,]      0      0      0      1      1
[6,]      1      0      0      1      1

Thanks for the report.