philchalmers / mirt

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

Do FIX and START work for experimental item? #58

Closed kwhkim closed 9 years ago

kwhkim commented 9 years ago

Since I have to use experimental items.. I pushed my modified package on my site...

Here's code to replicate the problem..


rm(list=ls())

R <-
structure(c(1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 3, 1, 2, 1, 2, 1, 1,
2, 1, 2, 1, 2, 1, 1, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1,
1, 1, 2, 2, 3, 3, 1, 1, 1, 1, 2, 1, 2, 2, 2, 2, 3, 2, 1, 2, 4,
1, 2, 2, 2, 1, 1, 4, 1, 1, 2, 1, 1, 3, 2, 1, 4, 1, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 2, 1, 1, 2, 3,
2, 4, 1, 3, 2, 2, 1, 1, 1, 3, 3, 2, 3, 2, 3, 3, 2, 1, 2, 3, 3,
3, 1, 1, 1, 3, 3, 2, 2, 3, 1, 3, 3, 1, 2, 2, 3, 1, 3, 2, 2, 3,
3, 1, 2, 3, 1, 3, 3, 2, 3, 2, 3, 3, 2, 1, 2, 4, 3, 2, 3, 2, 2,
1, 4, 1, 3, 3, 1, 3, 3, 2, 3, 4, 1, 3, 3, 3, 2, 2, 3, 3, 3, 2,
2, 3, 1, 2, 1, 1, 1, 2, 2, 3, 3, 3, 1, 3, 2, 3, 2, 1, 4, 2, 2,
2, 1, 1, 1, 4, 1, 4, 4, 2, 3, 3, 2, 3, 2, 4, 3, 4, 4, 1, 1, 4,
4, 3, 2, 3, 1, 3, 1, 1, 2, 2, 2, 1, 3, 2, 2, 2, 4, 1, 4, 1, 1,
4, 3, 1, 3, 3, 4, 3, 2, 1, 2, 4, 3, 4, 4, 2, 1, 1, 4, 1, 3, 3,
1, 1, 3, 2, 4, 4, 1, 3, 3, 3, 2, 4, 3, 4, 1, 2, 2, 2, 1, 1, 1,
1, 1, 2, 2, 1, 2, 3, 1, 1, 2, 3, 2, 1, 3, 1, 2, 1, 1, 1, 1, 4,
1, 4, 1, 2, 3, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 2, 1,
3, 1, 1, 2, 3, 1, 1, 2, 2, 3, 3, 4, 1, 2, 1, 1, 1, 1, 1, 4, 1,
3, 3, 2, 1, 2, 1, 3, 4, 3, 1, 3, 1, 4, 1, 3, 1, 1, 1, 3, 2, 1,
2, 1, 2, 2, 1, 2, 3, 1, 3, 1, 2, 2, 1, 1, 3, 1, 1, 1, 2, 2, 2,
1, 2, 1, 3, 2, 1, 2, 1, 1, 2, 2, 1, 1, 1, 1, 4, 4, 1, 4, 2, 2,
1, 1, 1, 2, 1, 1, 4, 1, 1, 1, 1, 3, 1, 2, 3, 1, 1, 1, 1, 2, 3,
3, 1, 2, 1, 3, 2, 4, 1, 2, 1, 1, 3, 1, 1, 4, 1, 3, 3, 2, 1, 2,
1, 3, 4, 1, 1, 1, 1, 2, 1, 1, 3, 1, 1, 3, 2, 1, 1, 1, 4, 4, 2,
2, 4, 1, 3, 3, 2, 2, 2, 1, 3, 1, 1, 1, 2, 2, 1, 1, 2, 1, 3, 2
), .Dim = c(100L, 5L))

ncat = function(R) {
stopifnot(is.matrix(R))
max(apply(R, 2, function(x) length(unique(x[!is.na(x)]))))
}

n.item <- ncol(R); ncat <- ncat(R)

# Do START and FIXED work?

model <- paste("F1 = 1-",n.item,
"\nCONSTRAIN = (1-",n.item,",d1)",
paste(",(1-",n.item,",d",2:(ncat-1),")",sep="", collapse=""),
"\nSTART = (1, c, 0.0)",
"\nFIXED = (1, c)",
sep="")

fit.grsm3_ <- mirt(R, mirt.model(model), itemtype=rep("grsm3", n.item))
coef2mat = function(cf) {
    stopifnot(is.list(cf))
    do.call(rbind, cf[1:(length(cf)-1)])
}

coef2mat(coef(fit.grsm3_))

Check if the c for first item is 0...

philchalmers commented 9 years ago

Wasn't able to reproduce with your code (those types aren't native to the master branch). I used this:

name <- 'old2PL'
par <- c(a = .5, b = -2)
est <- c(TRUE, TRUE)
P.old2PL <- function(par,Theta, ncat){
    a <- par[1]
    b <- par[2]
    P1 <- 1 / (1 + exp(-1*a*(Theta - b)))
    cbind(1-P1, P1)
}

x <- createItem(name, par=par, est=est, P=P.old2PL)

dat <- expand.table(LSAT7)
model <- 'F = 1-5
          START = (1, a1, 0.0), (5, a, 0.0)
          FIXED = (5, a)'
sv <- mirt(dat, model, c(rep('2PL',4), 'old2PL'), customItems=list(old2PL=x), pars = 'values')
tail(sv)

Seems to work fine now, thanks.

kwhkim commented 9 years ago

Oh I updated my fork and I works seamlessly. Thank you.