library(mirt)
library(eRm)
# Simulation of dichotomous data
set.seed(3)
n_items <- 40
n_cand <- 1000
diff <- rnorm(n_items, 0, 1) |> sort()
abilities <- rnorm(n_cand, 0, 1)
sim_data <- sapply(1:n_items, \(i) as.numeric(1 / (1 + exp ((diff[i] - abilities))) >
runif(n_cand, 0, 1)))
colnames(sim_data) <- paste0("Item ", seq_len(n_items))
## MIRT
model.mirt <- mirt(sim_data, 1, itemtype = "Rasch", verbose = FALSE)
res.mirt <- mirt::itemfit(model.mirt, 'infit')
# eRM
model.erm <- RM(sim_data)
res.erm <- person.parameter(model.erm) |> eRm::itemfit()
# All the following correlations are not equal to 1 (and far from it)
cor(res.mirt[, "infit"], res.erm$i.infitMSQ, method = "spearman")
cor(res.mirt[, "z.infit"], res.erm$i.infitZ, method = "spearman")
cor(res.mirt[, "outfit"], res.erm$i.outfitMSQ, method = "spearman")
cor(res.mirt[, "z.outfit"], res.erm$i.outfitZ, method = "spearman")
The items' difficulties are the same
item_mirt <- coef(model.mirt, IRTpars = TRUE, simplify = TRUE)$items[, "b"]
item_erm <- - coef(model.erm)
cor(item_mirt, item_erm, method = "spearman")
# [1] 1