R/sumScoreToIRT.R

Defines functions sumScoreToIRT

# Get the inverse of the expected score funtion from mirt or optimal score model
sumScoreToIRT <- function(sumScore, mirtModel=NULL, thetamin=0, thetamax=100,
                                   wfdList=NULL, optList=NULL, prec=0.0001, verbose=F) {
    theta <- thetamin+(thetamax-thetamin)/2
    jump <- (thetamax-thetamin)/4
    up <- NULL
    if (verbose) {
        print("----")
    }
    while (TRUE) {
        if (is.null(mirtModel)) {
            guess <- testscore(theta, wfdList, optList)
        }
        else {
            guess <- expected.test(mirtModel, matrix(theta, ncol = 1))
        }

        diff <- guess-sumScore
        if (verbose) {
            print(paste("sum:", guess, " theta:", theta, sep = ""))
        }
        if (abs(diff) < prec) {
            return(theta)
        }

        if (guess > sumScore) {
            if (theta==thetamin) {
                return(theta)
            }

            if (!is.null(up)) {
                if (up) {
                    jump <- jump/2
                }
            }
            up <- FALSE
            theta <- max(theta-jump, thetamin)
        }
        else {
            if (theta==thetamax) {
                return(theta)
            }

            if (!is.null(up)) {
                if (!up) {
                    jump <- jump/2
                }
            }
            up <- TRUE
            theta <- min(theta+jump, thetamax)
        }
    }
}
joakimwallmark/PolyOptimalIRT documentation built on Dec. 21, 2021, 1:16 a.m.