R/simulate.R

Defines functions simulate

library(mirt)
library(TestGardener)
# dataGenerationModel is a WfdList or mirt object
# R is iteration, theta is true scores with length of sample size
# dataGenerationModelType is list of models and config for each model. Can be optimal, graded och gpcm
# modelsToCompare is a vector with combinations of optimal and/or (graded or gpcm)
# thetas is a (sequence) vector of index values to fit models in each iteration
# optScr is list of score options, required when fitting optimal scores models
simulate <- function(R, dataGenerationModel, thetas,
                     dataGenerationModelType="optimal",
                     modelsToCompare=list(c("gpcm", "EAP"), c("gpcm", "ML"), c("optimal", cycles=15)),
                     optScr=NULL,
                     usePrecalibrated=F,
                     preCalibratedOptimal=NULL,
                     preCalibratedParMod=NULL) {
    n <- length(thetas)
    res <- matrix(NA, nrow = 0, ncol = n+1)
    for (r in 1:R) {
        resMat <- simulationIteration(r, n, dataGenerationModel, thetas,
                                     dataGenerationModelType,
                                     modelsToCompare,
                                     optScr,
                                     usePrecalibrated,
                                     preCalibratedOptimal,
                                     preCalibratedParMod)
        res <- rbind(res, resMat)
    }

    return(list(truethetas = thetas, simRes = res))
}
joakimwallmark/PolyOptimalIRT documentation built on Dec. 21, 2021, 1:16 a.m.