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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744150071a4560607.html
评论列表(0条)