R/nonparametricirt.h.R

Defines functions nonParametricIRT

# This file is automatically generated, you probably don't want to edit this

nonParametricIRTOptions <- if (requireNamespace('jmvcore')) R6::R6Class(
    "nonParametricIRTOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            item = NULL,
            group = NULL,
            format = "formatMC",
            miss = "option",
            NAweight = 0,
            OCCoption = "1",
            itemPlotOCC = FALSE,
            itemPlotEIS = FALSE,
            itemPlotOCCDIF = FALSE,
            itemPlotEISDIF = FALSE,
            pairwisePlotsDIF = FALSE,
            itemPlotSupplier = NULL,
            axisTypeTest = "score",
            axisTypeItem = "score",
            testPlotDensityDIF = FALSE,
            testPlotExpectedDIF = FALSE,
            testPlotSDDIF = FALSE,
            testPlotDensity = FALSE,
            testPlotExpected = FALSE,
            testPlotSD = FALSE,
            resTable = FALSE, ...) {

            super$initialize(
                package='psychoPDA',
                name='nonParametricIRT',
                requiresData=TRUE,
                ...)

            private$..item <- jmvcore::OptionVariables$new(
                "item",
                item,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..group <- jmvcore::OptionVariable$new(
                "group",
                group,
                suggested=list(
                    "ordinal"),
                permitted=list(
                    "factor"))
            private$..format <- jmvcore::OptionList$new(
                "format",
                format,
                options=list(
                    "formatMC",
                    "formatPartial",
                    "formatNominal"),
                default="formatMC")
            private$..miss <- jmvcore::OptionList$new(
                "miss",
                miss,
                options=list(
                    "option",
                    "random.unif",
                    "random.multinom",
                    "omit"),
                default="option")
            private$..NAweight <- jmvcore::OptionNumber$new(
                "NAweight",
                NAweight,
                min=0,
                max=1,
                default=0)
            private$..OCCoption <- jmvcore::OptionString$new(
                "OCCoption",
                OCCoption,
                default="1")
            private$..itemPlotOCC <- jmvcore::OptionBool$new(
                "itemPlotOCC",
                itemPlotOCC,
                default=FALSE)
            private$..itemPlotEIS <- jmvcore::OptionBool$new(
                "itemPlotEIS",
                itemPlotEIS,
                default=FALSE)
            private$..itemPlotOCCDIF <- jmvcore::OptionBool$new(
                "itemPlotOCCDIF",
                itemPlotOCCDIF,
                default=FALSE)
            private$..itemPlotEISDIF <- jmvcore::OptionBool$new(
                "itemPlotEISDIF",
                itemPlotEISDIF,
                default=FALSE)
            private$..pairwisePlotsDIF <- jmvcore::OptionBool$new(
                "pairwisePlotsDIF",
                pairwisePlotsDIF,
                default=FALSE)
            private$..itemPlotSupplier <- jmvcore::OptionVariables$new(
                "itemPlotSupplier",
                itemPlotSupplier)
            private$..axisTypeTest <- jmvcore::OptionList$new(
                "axisTypeTest",
                axisTypeTest,
                options=list(
                    "distribution",
                    "score"),
                default="score")
            private$..axisTypeItem <- jmvcore::OptionList$new(
                "axisTypeItem",
                axisTypeItem,
                options=list(
                    "distribution",
                    "score"),
                default="score")
            private$..testPlotDensityDIF <- jmvcore::OptionBool$new(
                "testPlotDensityDIF",
                testPlotDensityDIF,
                default=FALSE)
            private$..testPlotExpectedDIF <- jmvcore::OptionBool$new(
                "testPlotExpectedDIF",
                testPlotExpectedDIF,
                default=FALSE)
            private$..testPlotSDDIF <- jmvcore::OptionBool$new(
                "testPlotSDDIF",
                testPlotSDDIF,
                default=FALSE)
            private$..testPlotDensity <- jmvcore::OptionBool$new(
                "testPlotDensity",
                testPlotDensity,
                default=FALSE)
            private$..testPlotExpected <- jmvcore::OptionBool$new(
                "testPlotExpected",
                testPlotExpected,
                default=FALSE)
            private$..testPlotSD <- jmvcore::OptionBool$new(
                "testPlotSD",
                testPlotSD,
                default=FALSE)
            private$..resTable <- jmvcore::OptionBool$new(
                "resTable",
                resTable,
                default=FALSE)

            self$.addOption(private$..item)
            self$.addOption(private$..group)
            self$.addOption(private$..format)
            self$.addOption(private$..miss)
            self$.addOption(private$..NAweight)
            self$.addOption(private$..OCCoption)
            self$.addOption(private$..itemPlotOCC)
            self$.addOption(private$..itemPlotEIS)
            self$.addOption(private$..itemPlotOCCDIF)
            self$.addOption(private$..itemPlotEISDIF)
            self$.addOption(private$..pairwisePlotsDIF)
            self$.addOption(private$..itemPlotSupplier)
            self$.addOption(private$..axisTypeTest)
            self$.addOption(private$..axisTypeItem)
            self$.addOption(private$..testPlotDensityDIF)
            self$.addOption(private$..testPlotExpectedDIF)
            self$.addOption(private$..testPlotSDDIF)
            self$.addOption(private$..testPlotDensity)
            self$.addOption(private$..testPlotExpected)
            self$.addOption(private$..testPlotSD)
            self$.addOption(private$..resTable)
        }),
    active = list(
        item = function() private$..item$value,
        group = function() private$..group$value,
        format = function() private$..format$value,
        miss = function() private$..miss$value,
        NAweight = function() private$..NAweight$value,
        OCCoption = function() private$..OCCoption$value,
        itemPlotOCC = function() private$..itemPlotOCC$value,
        itemPlotEIS = function() private$..itemPlotEIS$value,
        itemPlotOCCDIF = function() private$..itemPlotOCCDIF$value,
        itemPlotEISDIF = function() private$..itemPlotEISDIF$value,
        pairwisePlotsDIF = function() private$..pairwisePlotsDIF$value,
        itemPlotSupplier = function() private$..itemPlotSupplier$value,
        axisTypeTest = function() private$..axisTypeTest$value,
        axisTypeItem = function() private$..axisTypeItem$value,
        testPlotDensityDIF = function() private$..testPlotDensityDIF$value,
        testPlotExpectedDIF = function() private$..testPlotExpectedDIF$value,
        testPlotSDDIF = function() private$..testPlotSDDIF$value,
        testPlotDensity = function() private$..testPlotDensity$value,
        testPlotExpected = function() private$..testPlotExpected$value,
        testPlotSD = function() private$..testPlotSD$value,
        resTable = function() private$..resTable$value),
    private = list(
        ..item = NA,
        ..group = NA,
        ..format = NA,
        ..miss = NA,
        ..NAweight = NA,
        ..OCCoption = NA,
        ..itemPlotOCC = NA,
        ..itemPlotEIS = NA,
        ..itemPlotOCCDIF = NA,
        ..itemPlotEISDIF = NA,
        ..pairwisePlotsDIF = NA,
        ..itemPlotSupplier = NA,
        ..axisTypeTest = NA,
        ..axisTypeItem = NA,
        ..testPlotDensityDIF = NA,
        ..testPlotExpectedDIF = NA,
        ..testPlotSDDIF = NA,
        ..testPlotDensity = NA,
        ..testPlotExpected = NA,
        ..testPlotSD = NA,
        ..resTable = NA)
)

nonParametricIRTResults <- if (requireNamespace('jmvcore')) R6::R6Class(
    inherit = jmvcore::Group,
    active = list(
        debug = function() private$.items[["debug"]],
        procedureNotes = function() private$.items[["procedureNotes"]],
        instructions = function() private$.items[["instructions"]],
        resTable = function() private$.items[["resTable"]],
        testPlotDensity = function() private$.items[["testPlotDensity"]],
        testPlotExpected = function() private$.items[["testPlotExpected"]],
        testPlotSD = function() private$.items[["testPlotSD"]],
        testPlotDensityDIF = function() private$.items[["testPlotDensityDIF"]],
        testPlotExpectedDIF = function() private$.items[["testPlotExpectedDIF"]],
        testPlotSDDIF = function() private$.items[["testPlotSDDIF"]],
        occPlots = function() private$.items[["occPlots"]],
        occPlotsDIF = function() private$.items[["occPlotsDIF"]],
        eisPlots = function() private$.items[["eisPlots"]],
        eisPlotsDIF = function() private$.items[["eisPlotsDIF"]],
        pairwisePlotsDIF = function() private$.items[["pairwisePlotsDIF"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Non-Parametric IRT")
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="debug",
                title="debug results"))
            self$add(jmvcore::Table$new(
                options=options,
                name="procedureNotes",
                title="Procedure Notes",
                visible=FALSE,
                rows=0,
                refs="NIRT",
                columns=list(
                    list(
                        `name`="bob", 
                        `title`="", 
                        `type`="text"))))
            self$add(jmvcore::Html$new(
                options=options,
                name="instructions",
                title="Instructions",
                visible=FALSE))
            self$add(jmvcore::Table$new(
                options=options,
                name="resTable",
                title="Polyserial Item-Total Correlation",
                visible="(resTable)",
                clearWith=list(
                    "item",
                    "group",
                    "format",
                    "SubRank",
                    "miss",
                    "NAweight",
                    "nevalpoints",
                    "kernel",
                    "bandwidth",
                    "RankFun",
                    "thetadist"),
                columns=list(
                    list(
                        `name`="Item", 
                        `title`="Item", 
                        `type`="text", 
                        `combineBelow`=TRUE),
                    list(
                        `name`="Correlation", 
                        `title`="Correlation", 
                        `type`="number", 
                        `format`="zto", 
                        `combineBelow`=TRUE),
                    list(
                        `name`="Option", 
                        `title`="Option", 
                        `type`="text"),
                    list(
                        `name`="N", 
                        `title`="N", 
                        `type`="number"))))
            self$add(jmvcore::Image$new(
                options=options,
                name="testPlotDensity",
                title="Density Plot",
                visible="(testPlotDensity)",
                width=550,
                height=450,
                renderFun=".testPlotDensity",
                clearWith=list(
                    "item",
                    "group",
                    "format",
                    "SubRank",
                    "miss",
                    "NAweight",
                    "nevalpoints",
                    "kernel",
                    "bandwidth",
                    "RankFun",
                    "thetadist",
                    "axisTypeTest")))
            self$add(jmvcore::Image$new(
                options=options,
                name="testPlotExpected",
                title="Expected Plot",
                visible="(testPlotExpected)",
                width=550,
                height=450,
                renderFun=".testPlotExpected",
                clearWith=list(
                    "item",
                    "group",
                    "format",
                    "SubRank",
                    "miss",
                    "NAweight",
                    "nevalpoints",
                    "kernel",
                    "bandwidth",
                    "RankFun",
                    "thetadist",
                    "axisTypeTest")))
            self$add(jmvcore::Image$new(
                options=options,
                name="testPlotSD",
                title="SD Plot",
                visible="(testPlotSD)",
                width=550,
                height=450,
                renderFun=".testPlotSD",
                clearWith=list(
                    "item",
                    "group",
                    "format",
                    "SubRank",
                    "miss",
                    "NAweight",
                    "nevalpoints",
                    "kernel",
                    "bandwidth",
                    "RankFun",
                    "thetadist",
                    "axisTypeTest")))
            self$add(jmvcore::Image$new(
                options=options,
                name="testPlotDensityDIF",
                title="Density Plot | DIF",
                visible="(testPlotDensityDIF)",
                width=550,
                height=450,
                renderFun=".testPlotDensityDIF",
                clearWith=list(
                    "item",
                    "group",
                    "format",
                    "SubRank",
                    "miss",
                    "NAweight",
                    "nevalpoints",
                    "kernel",
                    "bandwidth",
                    "RankFun",
                    "thetadist",
                    "axisTypeTest")))
            self$add(jmvcore::Image$new(
                options=options,
                name="testPlotExpectedDIF",
                title="Expected Plot | DIF",
                visible="(testPlotExpectedDIF)",
                width=550,
                height=450,
                renderFun=".testPlotExpectedDIF",
                clearWith=list(
                    "item",
                    "group",
                    "format",
                    "SubRank",
                    "miss",
                    "NAweight",
                    "nevalpoints",
                    "kernel",
                    "bandwidth",
                    "RankFun",
                    "thetadist",
                    "axisTypeTest")))
            self$add(jmvcore::Image$new(
                options=options,
                name="testPlotSDDIF",
                title="SD Plot | DIF",
                visible="(testPlotSDDIF)",
                width=550,
                height=450,
                renderFun=".testPlotSDDIF",
                clearWith=list(
                    "item",
                    "group",
                    "format",
                    "SubRank",
                    "miss",
                    "NAweight",
                    "nevalpoints",
                    "kernel",
                    "bandwidth",
                    "RankFun",
                    "thetadist",
                    "axisTypeTest")))
            self$add(jmvcore::Array$new(
                options=options,
                name="occPlots",
                title="OCC Plots",
                items="(itemPlotSupplier)",
                template=jmvcore::Image$new(
                    options=options,
                    width=550,
                    height=450,
                    renderFun=".occPlot",
                    visible="(itemPlotOCC)",
                    clearWith=list(
                        "item",
                        "group",
                        "format",
                        "SubRank",
                        "miss",
                        "NAweight",
                        "nevalpoints",
                        "kernel",
                        "bandwidth",
                        "RankFun",
                        "thetadist"))))
            self$add(jmvcore::Array$new(
                options=options,
                name="occPlotsDIF",
                title="OCC Plots DIF",
                items="(itemPlotSupplier)",
                template=jmvcore::Image$new(
                    options=options,
                    width=550,
                    height=450,
                    renderFun=".occPlotDIF",
                    visible="(itemPlotOCCDIF)",
                    clearWith=list(
                        "item",
                        "group",
                        "format",
                        "SubRank",
                        "miss",
                        "NAweight",
                        "nevalpoints",
                        "kernel",
                        "bandwidth",
                        "RankFun",
                        "thetadist"))))
            self$add(jmvcore::Array$new(
                options=options,
                name="eisPlots",
                title="EIS Plots",
                items="(itemPlotSupplier)",
                template=jmvcore::Image$new(
                    options=options,
                    width=550,
                    height=450,
                    renderFun=".eisPlot",
                    visible="(itemPlotEIS)",
                    clearWith=list(
                        "item",
                        "group",
                        "format",
                        "SubRank",
                        "miss",
                        "NAweight",
                        "nevalpoints",
                        "kernel",
                        "bandwidth",
                        "RankFun",
                        "thetadist",
                        "axisTypeItem"))))
            self$add(jmvcore::Array$new(
                options=options,
                name="eisPlotsDIF",
                title="EIS Plots | DIF",
                items="(itemPlotSupplier)",
                template=jmvcore::Image$new(
                    options=options,
                    width=550,
                    height=450,
                    renderFun=".eisPlotDIF",
                    visible="(itemPlotEISDIF)",
                    clearWith=list(
                        "item",
                        "group",
                        "format",
                        "SubRank",
                        "miss",
                        "NAweight",
                        "nevalpoints",
                        "kernel",
                        "bandwidth",
                        "RankFun",
                        "thetadist"))))
            self$add(jmvcore::Array$new(
                options=options,
                name="pairwisePlotsDIF",
                title="Pairwise EIS | DIF",
                items="(itemPlotSupplier)",
                template=jmvcore::Image$new(
                    options=options,
                    width=550,
                    height=450,
                    renderFun=".pairwisePlotsDIF",
                    visible="(pairwisePlotsDIF)",
                    clearWith=list(
                        "item",
                        "group",
                        "format",
                        "SubRank",
                        "miss",
                        "NAweight",
                        "nevalpoints",
                        "kernel",
                        "bandwidth",
                        "RankFun",
                        "thetadist"))))}))

nonParametricIRTBase <- if (requireNamespace('jmvcore')) R6::R6Class(
    "nonParametricIRTBase",
    inherit = jmvcore::Analysis,
    public = list(
        initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
            super$initialize(
                package = 'psychoPDA',
                name = 'nonParametricIRT',
                version = c(1,0,0),
                options = options,
                results = nonParametricIRTResults$new(options=options),
                data = data,
                datasetId = datasetId,
                analysisId = analysisId,
                revision = revision,
                pause = NULL,
                completeWhenFilled = FALSE,
                requiresMissings = FALSE)
        }))

#' Non-Parametric IRT
#'
#' 
#' @param data .
#' @param item .
#' @param group .
#' @param format .
#' @param miss .
#' @param NAweight .
#' @param OCCoption .
#' @param itemPlotOCC .
#' @param itemPlotEIS .
#' @param itemPlotOCCDIF .
#' @param itemPlotEISDIF .
#' @param pairwisePlotsDIF .
#' @param itemPlotSupplier .
#' @param axisTypeTest .
#' @param axisTypeItem .
#' @param testPlotDensityDIF .
#' @param testPlotExpectedDIF .
#' @param testPlotSDDIF .
#' @param testPlotDensity .
#' @param testPlotExpected .
#' @param testPlotSD .
#' @param resTable .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$debug} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$procedureNotes} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$instructions} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$resTable} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$testPlotDensity} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$testPlotExpected} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$testPlotSD} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$testPlotDensityDIF} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$testPlotExpectedDIF} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$testPlotSDDIF} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$occPlots} \tab \tab \tab \tab \tab an array of images \cr
#'   \code{results$occPlotsDIF} \tab \tab \tab \tab \tab an array of images \cr
#'   \code{results$eisPlots} \tab \tab \tab \tab \tab an array of images \cr
#'   \code{results$eisPlotsDIF} \tab \tab \tab \tab \tab an array of images \cr
#'   \code{results$pairwisePlotsDIF} \tab \tab \tab \tab \tab an array of images \cr
#' }
#'
#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example:
#'
#' \code{results$procedureNotes$asDF}
#'
#' \code{as.data.frame(results$procedureNotes)}
#'
#' @export
nonParametricIRT <- function(
    data,
    item,
    group,
    format = "formatMC",
    miss = "option",
    NAweight = 0,
    OCCoption = "1",
    itemPlotOCC = FALSE,
    itemPlotEIS = FALSE,
    itemPlotOCCDIF = FALSE,
    itemPlotEISDIF = FALSE,
    pairwisePlotsDIF = FALSE,
    itemPlotSupplier,
    axisTypeTest = "score",
    axisTypeItem = "score",
    testPlotDensityDIF = FALSE,
    testPlotExpectedDIF = FALSE,
    testPlotSDDIF = FALSE,
    testPlotDensity = FALSE,
    testPlotExpected = FALSE,
    testPlotSD = FALSE,
    resTable = FALSE) {

    if ( ! requireNamespace('jmvcore'))
        stop('nonParametricIRT requires jmvcore to be installed (restart may be required)')

    if ( ! missing(item)) item <- jmvcore::resolveQuo(jmvcore::enquo(item))
    if ( ! missing(group)) group <- jmvcore::resolveQuo(jmvcore::enquo(group))
    if ( ! missing(itemPlotSupplier)) itemPlotSupplier <- jmvcore::resolveQuo(jmvcore::enquo(itemPlotSupplier))
    if (missing(data))
        data <- jmvcore::marshalData(
            parent.frame(),
            `if`( ! missing(item), item, NULL),
            `if`( ! missing(group), group, NULL),
            `if`( ! missing(itemPlotSupplier), itemPlotSupplier, NULL))

    for (v in group) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])

    options <- nonParametricIRTOptions$new(
        item = item,
        group = group,
        format = format,
        miss = miss,
        NAweight = NAweight,
        OCCoption = OCCoption,
        itemPlotOCC = itemPlotOCC,
        itemPlotEIS = itemPlotEIS,
        itemPlotOCCDIF = itemPlotOCCDIF,
        itemPlotEISDIF = itemPlotEISDIF,
        pairwisePlotsDIF = pairwisePlotsDIF,
        itemPlotSupplier = itemPlotSupplier,
        axisTypeTest = axisTypeTest,
        axisTypeItem = axisTypeItem,
        testPlotDensityDIF = testPlotDensityDIF,
        testPlotExpectedDIF = testPlotExpectedDIF,
        testPlotSDDIF = testPlotSDDIF,
        testPlotDensity = testPlotDensity,
        testPlotExpected = testPlotExpected,
        testPlotSD = testPlotSD,
        resTable = resTable)

    analysis <- nonParametricIRTClass$new(
        options = options,
        data = data)

    analysis$run()

    analysis$results
}
lucasjfriesen/jamoviPsychoPDA documentation built on May 23, 2021, 5:20 p.m.