admin管理员组文章数量:1397199
This is the follow-up question from this question
How can I fix parameters for some items but not all?
# Simulate data
set.seed(1)
dat <- matrix(sample(c(0,1), 100, TRUE), ncol = 5)
colnames(dat) <- paste0('item', 1:5)
# Fit a model and extract parameters of items
library(mirt)
mod <- mirt(dat, model = 1, itemtype = '2PL')
param <- mod2values(mod)
param$est <- F
# Works with the former data
mod2 <- mirt(dat, model = 1, itemtype = '2PL', pars = param)
# Doesn't work with new columns
new.data <- cbind(dat, item6 = sample(c(0,1), 20, TRUE))
mod3 <- mirt(new.data, model = 1, itemtype = '2PL', pars = param)
# Error: itemtype specification is not the correct length
# In addition: Warning messages:
# 1: EM cycles terminated after 500 iterations.
# 2: In itemtype %in% c("2PLNRM", "3PLNRM", "3PLuNRM", "4PLNRM") & K < :
# longer object length is not a multiple of shorter object length
This is the follow-up question from this question
How can I fix parameters for some items but not all?
# Simulate data
set.seed(1)
dat <- matrix(sample(c(0,1), 100, TRUE), ncol = 5)
colnames(dat) <- paste0('item', 1:5)
# Fit a model and extract parameters of items
library(mirt)
mod <- mirt(dat, model = 1, itemtype = '2PL')
param <- mod2values(mod)
param$est <- F
# Works with the former data
mod2 <- mirt(dat, model = 1, itemtype = '2PL', pars = param)
# Doesn't work with new columns
new.data <- cbind(dat, item6 = sample(c(0,1), 20, TRUE))
mod3 <- mirt(new.data, model = 1, itemtype = '2PL', pars = param)
# Error: itemtype specification is not the correct length
# In addition: Warning messages:
# 1: EM cycles terminated after 500 iterations.
# 2: In itemtype %in% c("2PLNRM", "3PLNRM", "3PLuNRM", "4PLNRM") & K < :
# longer object length is not a multiple of shorter object length
Share
Improve this question
edited Mar 26 at 13:19
Julien
asked Mar 26 at 10:47
JulienJulien
1,7721 gold badge14 silver badges32 bronze badges
1 Answer
Reset to default 1The error occurs because param
from the model with 5 items doesn’t include parameter specifications for the new sixth item. In other words, when you add a new item, mirt
expects a parameter table that includes parameters for all items in the data.
So you can add this to your code:
param_new <- mod2values(mirt(new.data, model = 1, itemtype = '2PL'))
# Replace parameters for items from the old table
# (if you want to keep params for item1 to item5)
for(i in paste0("item", 1:5)){
param_new[param_new$item == i, ] <- param[param$item == i, ]
}
mod3 <- mirt(new.data, model = 1, itemtype = '2PL', pars = param_new)
本文标签: How to fix parameters for some items with the mirt package in RStack Overflow
版权声明:本文标题:How to fix parameters for some items with the `mirt` package in R? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744150071a2593021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论