R/ppv.h.R

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

ppvOptions <- if (requireNamespace('jmvcore')) R6::R6Class(
    "ppvOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            percTrue = 50,
            alpha = 0.05,
            power = 0.8,
            percHack = 0, ...) {

            super$initialize(
                package='ppv',
                name='ppv',
                requiresData=FALSE,
                ...)
        
            private$..percTrue <- jmvcore::OptionInteger$new(
                "percTrue",
                percTrue,
                min=0,
                max=100,
                default=50)
            private$..alpha <- jmvcore::OptionNumber$new(
                "alpha",
                alpha,
                min=0.01,
                max=0.1,
                default=0.05)
            private$..power <- jmvcore::OptionNumber$new(
                "power",
                power,
                min=0.01,
                max=0.99,
                default=0.8)
            private$..percHack <- jmvcore::OptionInteger$new(
                "percHack",
                percHack,
                min=0,
                max=100,
                default=0)
        
            self$.addOption(private$..percTrue)
            self$.addOption(private$..alpha)
            self$.addOption(private$..power)
            self$.addOption(private$..percHack)
        }),
    active = list(
        percTrue = function() private$..percTrue$value,
        alpha = function() private$..alpha$value,
        power = function() private$..power$value,
        percHack = function() private$..percHack$value),
    private = list(
        ..percTrue = NA,
        ..alpha = NA,
        ..power = NA,
        ..percHack = NA)
)

ppvResults <- if (requireNamespace('jmvcore')) R6::R6Class(
    inherit = jmvcore::Group,
    active = list(
        confusion = function() private$..confusion,
        ppv = function() private$..ppv,
        dotPlot = function() private$..dotPlot),
    private = list(
        ..confusion = NA,
        ..ppv = NA,
        ..dotPlot = NA),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Positive Predictive Value")
            private$..confusion <- jmvcore::Table$new(
                options=options,
                name="confusion",
                title="Percentages",
                rows=1,
                clearWith=list(
                    "percTrue",
                    "alpha",
                    "power",
                    "percHack"),
                columns=list(
                    list(
                        `name`="name[pos]", 
                        `title`="Claimed Finding", 
                        `type`="text", 
                        `content`="Postive"),
                    list(
                        `name`="false[pos]", 
                        `title`="H<sub>0</sub> True", 
                        `type`="number", 
                        `superTitle`="Truth"),
                    list(
                        `name`="true[pos]", 
                        `title`="H<sub>a</sub> True", 
                        `type`="number", 
                        `superTitle`="Truth"),
                    list(
                        `name`="total[pos]", 
                        `title`="Total", 
                        `type`="number"),
                    list(
                        `name`="name[neg]", 
                        `title`="Claimed Finding", 
                        `type`="text", 
                        `content`="Negative"),
                    list(
                        `name`="false[neg]", 
                        `title`="H<sub>0</sub> True", 
                        `type`="number", 
                        `superTitle`="Truth"),
                    list(
                        `name`="true[neg]", 
                        `title`="H<sub>a</sub> True", 
                        `type`="number", 
                        `superTitle`="Truth"),
                    list(
                        `name`="total[neg]", 
                        `title`="Total", 
                        `type`="number"),
                    list(
                        `name`="name[total]", 
                        `title`="Claimed Finding", 
                        `type`="text", 
                        `content`="Total"),
                    list(
                        `name`="false[total]", 
                        `title`="H<sub>0</sub> True", 
                        `type`="number", 
                        `superTitle`="Truth"),
                    list(
                        `name`="true[total]", 
                        `title`="H<sub>a</sub> True", 
                        `type`="number", 
                        `superTitle`="Truth"),
                    list(
                        `name`="total[total]", 
                        `title`="Total", 
                        `type`="number")))
            private$..ppv <- jmvcore::Html$new(
                options=options,
                name="ppv",
                title="Positive Predictive Value")
            private$..dotPlot <- jmvcore::Image$new(
                options=options,
                name="dotPlot",
                title="Study Outcomes",
                width=550,
                height=400,
                renderFun=".dotPlot",
                clearWith=list(
                    "percTrue",
                    "alpha",
                    "power",
                    "percHack"))
            self$add(private$..confusion)
            self$add(private$..ppv)
            self$add(private$..dotPlot)}))

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

#' Positive Predictive Value
#'
#' 
#' @param percTrue .
#' @param alpha .
#' @param power .
#' @param percHack .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$confusion} \tab \tab \tab \tab \tab a table containing the true/false positives/negatives \cr
#'   \code{results$ppv} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$dotPlot} \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$confusion$asDF}
#'
#' \code{as.data.frame(results$confusion)}
#'
#' @export
ppv <- function(
    percTrue = 50,
    alpha = 0.05,
    power = 0.8,
    percHack = 0) {

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

    options <- ppvOptions$new(
        percTrue = percTrue,
        alpha = alpha,
        power = power,
        percHack = percHack)

    results <- ppvResults$new(
        options = options)

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

    analysis$run()

    analysis$results
}
raviselker/ppv documentation built on May 30, 2019, 4:40 p.m.