tests/testthat/test-sumScoreToIRT.R

library(TestGardener)
library(mirt)

test_that("sum score gives correct optimal score", {
    load("../../data/NatMath_fittedmodel.RData")
    res <- sumScoreToIRT(11.929263, wfdList = AnalyzeResult$parList[[10]]$WfdList,
                         optList = NatMath_dataList$optList)
    res2 <- sumScoreToIRT(1, wfdList = AnalyzeResult$parList[[10]]$WfdList,
                          optList = NatMath_dataList$optList)
    res3 <- sumScoreToIRT(55, wfdList = AnalyzeResult$parList[[10]]$WfdList,
                          optList = NatMath_dataList$optList)
    expect_equal(c(round(res, digits = 3), res2, res3), c(5.106, 0, 100))

    load("../../data/NatMath_fittedmodel_mirt.RData")
    res <- sumScoreToIRT(12.100827, mirtModel = natMathGpcm, thetamin = -3.5,
                        thetamax = 3.5, verbose = T)
    res2 <- sumScoreToIRT(1, mirtModel = natMathGpcm, thetamin = -3.5,
                        thetamax = 3.5, verbose = T)
    res3 <- sumScoreToIRT(57, mirtModel = natMathGpcm, thetamin = -3.5,
                        thetamax = 3.5, verbose = T)
    expect_equal(c(round(res, digits = 3), res2, res3), c(-1.234, -3.5, 3.5))

    # back and forth results in the same?
    res1 <- sumScoreToIRT(20, mirtModel = natMathGpcm, thetamin = -3.5,
                         thetamax = 3.5, verbose = T)
    expect_equal(round(expected.test(natMathGpcm, matrix(res1, ncol = 1)), 3), 20)

    res <- sumScoreToIRT(20, wfdList = AnalyzeResult$parList[[10]]$WfdList,
                         optList = NatMath_dataList$optList)
    expect_equal(round(testscore(res, AnalyzeResult$parList[[10]]$WfdList,
                           NatMath_dataList$optList), 3), 20)
})
joakimwallmark/PolyOptimalIRT documentation built on Dec. 21, 2021, 1:16 a.m.