R/screeningcalculator.h.R

Defines functions screeningcalculator

Documented in screeningcalculator

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

screeningcalculatorOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "screeningcalculatorOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            sens = 0.9,
            spec = 0.8,
            prev = 0.1,
            repeat2 = TRUE,
            repeat3 = TRUE,
            fnote = FALSE,
            fagan = FALSE, ...) {

            super$initialize(
                package="ClinicoPath",
                name="screeningcalculator",
                requiresData=FALSE,
                ...)

            private$..sens <- jmvcore::OptionNumber$new(
                "sens",
                sens,
                default=0.9,
                min=0.01,
                max=0.99)
            private$..spec <- jmvcore::OptionNumber$new(
                "spec",
                spec,
                default=0.8,
                min=0.01,
                max=0.99)
            private$..prev <- jmvcore::OptionNumber$new(
                "prev",
                prev,
                default=0.1,
                min=0.001,
                max=0.999)
            private$..repeat2 <- jmvcore::OptionBool$new(
                "repeat2",
                repeat2,
                default=TRUE)
            private$..repeat3 <- jmvcore::OptionBool$new(
                "repeat3",
                repeat3,
                default=TRUE)
            private$..fnote <- jmvcore::OptionBool$new(
                "fnote",
                fnote,
                default=FALSE)
            private$..fagan <- jmvcore::OptionBool$new(
                "fagan",
                fagan,
                default=FALSE)

            self$.addOption(private$..sens)
            self$.addOption(private$..spec)
            self$.addOption(private$..prev)
            self$.addOption(private$..repeat2)
            self$.addOption(private$..repeat3)
            self$.addOption(private$..fnote)
            self$.addOption(private$..fagan)
        }),
    active = list(
        sens = function() private$..sens$value,
        spec = function() private$..spec$value,
        prev = function() private$..prev$value,
        repeat2 = function() private$..repeat2$value,
        repeat3 = function() private$..repeat3$value,
        fnote = function() private$..fnote$value,
        fagan = function() private$..fagan$value),
    private = list(
        ..sens = NA,
        ..spec = NA,
        ..prev = NA,
        ..repeat2 = NA,
        ..repeat3 = NA,
        ..fnote = NA,
        ..fagan = NA)
)

screeningcalculatorResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "screeningcalculatorResults",
    inherit = jmvcore::Group,
    active = list(
        explanatoryText = function() private$.items[["explanatoryText"]],
        mathText = function() private$.items[["mathText"]],
        singleTestTable = function() private$.items[["singleTestTable"]],
        repeatTest2Table = function() private$.items[["repeatTest2Table"]],
        repeatTest3Table = function() private$.items[["repeatTest3Table"]],
        plot1 = function() private$.items[["plot1"]],
        plot2PP = function() private$.items[["plot2PP"]],
        plot2NN = function() private$.items[["plot2NN"]],
        plot3PPP = function() private$.items[["plot3PPP"]],
        plot3NNN = function() private$.items[["plot3NNN"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Screening Test Calculator",
                refs=list(
                    "DiagnosticTests",
                    "sensspecwiki"))
            self$add(jmvcore::Html$new(
                options=options,
                name="explanatoryText",
                title="How Sequential Testing Works"))
            self$add(jmvcore::Html$new(
                options=options,
                name="mathText",
                title="Math Behind the Calculations"))
            self$add(jmvcore::Table$new(
                options=options,
                name="singleTestTable",
                title="Single Test Results",
                swapRowsColumns=TRUE,
                rows=1,
                columns=list(
                    list(
                        `name`="tablename", 
                        `title`="", 
                        `type`="text"),
                    list(
                        `name`="Sensitivity", 
                        `title`="Sensitivity", 
                        `type`="number", 
                        `format`="pc"),
                    list(
                        `name`="Specificity", 
                        `title`="Specificity", 
                        `type`="number", 
                        `format`="pc"),
                    list(
                        `name`="Prevalence", 
                        `title`="Prevalence", 
                        `type`="number", 
                        `format`="pc"),
                    list(
                        `name`="PPV", 
                        `title`="Positive Predictive Value", 
                        `type`="number", 
                        `format`="pc"),
                    list(
                        `name`="NPV", 
                        `title`="Negative Predictive Value", 
                        `type`="number", 
                        `format`="pc"),
                    list(
                        `name`="LRP", 
                        `title`="Positive Likelihood Ratio", 
                        `type`="number"),
                    list(
                        `name`="LRN", 
                        `title`="Negative Likelihood Ratio", 
                        `type`="number"))))
            self$add(jmvcore::Table$new(
                options=options,
                name="repeatTest2Table",
                title="Two Consecutive Tests",
                visible="(repeat2)",
                rows=0,
                columns=list(
                    list(
                        `name`="testResult", 
                        `title`="Test Result Pattern", 
                        `type`="text"),
                    list(
                        `name`="probDisease", 
                        `title`="Probability of Disease", 
                        `type`="number", 
                        `format`="pc"),
                    list(
                        `name`="explanation", 
                        `title`="Interpretation", 
                        `type`="text"))))
            self$add(jmvcore::Table$new(
                options=options,
                name="repeatTest3Table",
                title="Three Consecutive Tests",
                visible="(repeat3)",
                rows=0,
                columns=list(
                    list(
                        `name`="testResult", 
                        `title`="Test Result Pattern", 
                        `type`="text"),
                    list(
                        `name`="probDisease", 
                        `title`="Probability of Disease", 
                        `type`="number", 
                        `format`="pc"),
                    list(
                        `name`="explanation", 
                        `title`="Interpretation", 
                        `type`="text"))))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot1",
                title="Fagan Nomogram (Single Test)",
                width=600,
                height=450,
                renderFun=".plot1",
                requiresData=TRUE,
                visible="(fagan)",
                clearWith=list(
                    "sens",
                    "spec",
                    "prev",
                    "fagan")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot2PP",
                title="Fagan Nomogram (Second Test after Positive)",
                width=600,
                height=450,
                renderFun=".plot2PP",
                requiresData=TRUE,
                visible="(fagan && repeat2)",
                clearWith=list(
                    "sens",
                    "spec",
                    "prev",
                    "fagan",
                    "repeat2")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot2NN",
                title="Fagan Nomogram (Second Test after Negative)",
                width=600,
                height=450,
                renderFun=".plot2NN",
                requiresData=TRUE,
                visible="(fagan && repeat2)",
                clearWith=list(
                    "sens",
                    "spec",
                    "prev",
                    "fagan",
                    "repeat2")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot3PPP",
                title="Fagan Nomogram (Third Test after Two Positives)",
                width=600,
                height=450,
                renderFun=".plot3PPP",
                requiresData=TRUE,
                visible="(fagan && repeat3)",
                clearWith=list(
                    "sens",
                    "spec",
                    "prev",
                    "fagan",
                    "repeat3")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot3NNN",
                title="Fagan Nomogram (Third Test after Two Negatives)",
                width=600,
                height=450,
                renderFun=".plot3NNN",
                requiresData=TRUE,
                visible="(fagan && repeat3)",
                clearWith=list(
                    "sens",
                    "spec",
                    "prev",
                    "fagan",
                    "repeat3")))}))

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

#' Screening Test Calculator
#'
#' Function for Screening Test Probability Calculator.
#'
#' @examples
#' \donttest{
#' # example will be added
#'}
#' @param sens .
#' @param spec .
#' @param prev .
#' @param repeat2 .
#' @param repeat3 .
#' @param fnote .
#' @param fagan .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$explanatoryText} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$mathText} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$singleTestTable} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$repeatTest2Table} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$repeatTest3Table} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$plot1} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot2PP} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot2NN} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot3PPP} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot3NNN} \tab \tab \tab \tab \tab an image \cr
#' }
#'
#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example:
#'
#' \code{results$singleTestTable$asDF}
#'
#' \code{as.data.frame(results$singleTestTable)}
#'
#' @export
screeningcalculator <- function(
    sens = 0.9,
    spec = 0.8,
    prev = 0.1,
    repeat2 = TRUE,
    repeat3 = TRUE,
    fnote = FALSE,
    fagan = FALSE) {

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


    options <- screeningcalculatorOptions$new(
        sens = sens,
        spec = spec,
        prev = prev,
        repeat2 = repeat2,
        repeat3 = repeat3,
        fnote = fnote,
        fagan = fagan)

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

    analysis$run()

    analysis$results
}
sbalci/ClinicoPathJamoviModule documentation built on June 13, 2025, 9:34 a.m.