sbalci/ClinicoPathJamoviModule

View on GitHub
R/roc.h.R

Summary

Maintainability
Test Coverage

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

rocOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "rocOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            measurement = NULL,
            status = NULL,
            excl = FALSE,
            sty = FALSE,
            quant = FALSE,
            label = FALSE,
            inter = FALSE, ...) {

            super$initialize(
                package="ClinicoPath",
                name="roc",
                requiresData=TRUE,
                ...)

            private$..measurement <- jmvcore::OptionVariable$new(
                "measurement",
                measurement)
            private$..status <- jmvcore::OptionVariable$new(
                "status",
                status)
            private$..excl <- jmvcore::OptionBool$new(
                "excl",
                excl,
                default=FALSE)
            private$..sty <- jmvcore::OptionBool$new(
                "sty",
                sty,
                default=FALSE)
            private$..quant <- jmvcore::OptionBool$new(
                "quant",
                quant,
                default=FALSE)
            private$..label <- jmvcore::OptionBool$new(
                "label",
                label,
                default=FALSE)
            private$..inter <- jmvcore::OptionBool$new(
                "inter",
                inter,
                default=FALSE)

            self$.addOption(private$..measurement)
            self$.addOption(private$..status)
            self$.addOption(private$..excl)
            self$.addOption(private$..sty)
            self$.addOption(private$..quant)
            self$.addOption(private$..label)
            self$.addOption(private$..inter)
        }),
    active = list(
        measurement = function() private$..measurement$value,
        status = function() private$..status$value,
        excl = function() private$..excl$value,
        sty = function() private$..sty$value,
        quant = function() private$..quant$value,
        label = function() private$..label$value,
        inter = function() private$..inter$value),
    private = list(
        ..measurement = NA,
        ..status = NA,
        ..excl = NA,
        ..sty = NA,
        ..quant = NA,
        ..label = NA,
        ..inter = NA)
)

rocResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "rocResults",
    inherit = jmvcore::Group,
    active = list(
        todo = function() private$.items[["todo"]],
        text = function() private$.items[["text"]],
        textplot = function() private$.items[["textplot"]],
        plot = function() private$.items[["plot"]],
        plot2 = function() private$.items[["plot2"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="ROC",
                refs=list(
                    "plotROC",
                    "ClinicoPathJamoviModule"))
            self$add(jmvcore::Html$new(
                options=options,
                name="todo",
                title="To Do",
                clearWith=list(
                    "measurement",
                    "status",
                    "excl",
                    "sty",
                    "quant",
                    "label",
                    "inter")))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="text",
                title="ROC text",
                clearWith=list(
                    "measurement",
                    "status",
                    "excl",
                    "sty",
                    "quant",
                    "label",
                    "inter")))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="textplot",
                title="ROC textplot",
                clearWith=list(
                    "measurement",
                    "status",
                    "excl",
                    "sty",
                    "quant",
                    "label",
                    "inter")))
            self$add(jmvcore::Image$new(
                options=options,
                title="ROC",
                name="plot",
                width=600,
                height=450,
                renderFun=".plot",
                requiresData=TRUE,
                clearWith=list(
                    "measurement",
                    "status",
                    "excl",
                    "sty",
                    "quant",
                    "label",
                    "inter")))
            self$add(jmvcore::Image$new(
                options=options,
                title="ROC Interactive",
                name="plot2",
                width=600,
                height=450,
                renderFun=".plot2",
                requiresData=TRUE,
                clearWith=list(
                    "measurement",
                    "status",
                    "excl"),
                visible="(inter)"))}))

rocBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "rocBase",
    inherit = jmvcore::Analysis,
    public = list(
        initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
            super$initialize(
                package = "ClinicoPath",
                name = "roc",
                version = c(1,0,0),
                options = options,
                results = rocResults$new(options=options),
                data = data,
                datasetId = datasetId,
                analysisId = analysisId,
                revision = revision,
                pause = NULL,
                completeWhenFilled = FALSE,
                requiresMissings = FALSE,
                weightsSupport = 'auto')
        }))

#' ROC
#'
#' Function for ROC Analysis.
#'
#' @examples
#' \dontrun{
#' # example will be added
#'}
#' @param data The data as a data frame.
#' @param measurement .
#' @param status .
#' @param excl .
#' @param sty .
#' @param quant .
#' @param label .
#' @param inter .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$todo} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$text} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$textplot} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot2} \tab \tab \tab \tab \tab an image \cr
#' }
#'
#' @export
roc <- function(
    data,
    measurement,
    status,
    excl = FALSE,
    sty = FALSE,
    quant = FALSE,
    label = FALSE,
    inter = FALSE) {

    if ( ! requireNamespace("jmvcore", quietly=TRUE))
        stop("roc requires jmvcore to be installed (restart may be required)")

    if ( ! missing(measurement)) measurement <- jmvcore::resolveQuo(jmvcore::enquo(measurement))
    if ( ! missing(status)) status <- jmvcore::resolveQuo(jmvcore::enquo(status))
    if (missing(data))
        data <- jmvcore::marshalData(
            parent.frame(),
            `if`( ! missing(measurement), measurement, NULL),
            `if`( ! missing(status), status, NULL))


    options <- rocOptions$new(
        measurement = measurement,
        status = status,
        excl = excl,
        sty = sty,
        quant = quant,
        label = label,
        inter = inter)

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

    analysis$run()

    analysis$results
}