##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function(items) {
ncases <- nrow(items)
item.mean <- colMeans(items,na.rm=TRUE)
item.mean[item.mean<(1/ncases)] <- 1/ncases
irt.item.diff.rasch <- log((1/item.mean)- 1) }
"irt.discrim" <-
function(item.diff,theta,items) {
#find the item discrimination parameter (beta)
#find the item discrimination parameter -- optimized by item.discrim
irt.item.discrim <- function(x,diff,theta,scores) {
fit <- -1*(log(scores/(1+exp(x*(diff-theta))) + (1-scores)/(1+exp(x*(theta-diff)))))
mean(fit,na.rm=TRUE)
}
nitems <- length(item.diff)
discrim <- matrix(NA,nitems,2)
for (i in 1:nitems) {
item.fit <- optimize(irt.item.discrim,c(-5,5),diff=item.diff[i],theta=theta,scores = items[,i])
discrim[i,1] <- item.fit$minimum
discrim[i,2] <- item.fit$objective}
irt.discrim <- discrim
}
Run the code above in your browser using DataLab