R/sumScoreToOptimalScore.R

Defines functions sumScoreToOptimalScore

sumScoreToOptimalScore <- function(sumScore, wfdList, optList, prec=0.0001, verbose=F) {
    theta <- 50
    jump <- theta/2
    bestguess <- Inf
    up <- NULL
    if (verbose) {
        print("----")
    }
    while (TRUE) {
        guess <- testscore(theta, wfdList, optList)
        diff <- guess-sumScore
        if (verbose) {
            print(paste("sum:", guess, " theta:", theta, sep = ""))
        }
        if (abs(diff) < prec) {
            return(theta)
        }

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

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

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