R/concordance.h.R

Defines functions concordance

Documented in concordance

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

concordanceOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "concordanceOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            dep = NULL,
            covs = NULL,
            cc = TRUE,
            ccp = FALSE,
            bap = FALSE,
            width = 500,
            height = 500,
            width1 = 500,
            height1 = 500, ...) {

            super$initialize(
                package="seolmatrix",
                name="concordance",
                requiresData=TRUE,
                ...)

            private$..dep <- jmvcore::OptionVariable$new(
                "dep",
                dep,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..covs <- jmvcore::OptionVariable$new(
                "covs",
                covs,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..cc <- jmvcore::OptionBool$new(
                "cc",
                cc,
                default=TRUE)
            private$..ccp <- jmvcore::OptionBool$new(
                "ccp",
                ccp,
                default=FALSE)
            private$..bap <- jmvcore::OptionBool$new(
                "bap",
                bap,
                default=FALSE)
            private$..width <- jmvcore::OptionInteger$new(
                "width",
                width,
                default=500)
            private$..height <- jmvcore::OptionInteger$new(
                "height",
                height,
                default=500)
            private$..width1 <- jmvcore::OptionInteger$new(
                "width1",
                width1,
                default=500)
            private$..height1 <- jmvcore::OptionInteger$new(
                "height1",
                height1,
                default=500)

            self$.addOption(private$..dep)
            self$.addOption(private$..covs)
            self$.addOption(private$..cc)
            self$.addOption(private$..ccp)
            self$.addOption(private$..bap)
            self$.addOption(private$..width)
            self$.addOption(private$..height)
            self$.addOption(private$..width1)
            self$.addOption(private$..height1)
        }),
    active = list(
        dep = function() private$..dep$value,
        covs = function() private$..covs$value,
        cc = function() private$..cc$value,
        ccp = function() private$..ccp$value,
        bap = function() private$..bap$value,
        width = function() private$..width$value,
        height = function() private$..height$value,
        width1 = function() private$..width1$value,
        height1 = function() private$..height1$value),
    private = list(
        ..dep = NA,
        ..covs = NA,
        ..cc = NA,
        ..ccp = NA,
        ..bap = NA,
        ..width = NA,
        ..height = NA,
        ..width1 = NA,
        ..height1 = NA)
)

concordanceResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "concordanceResults",
    inherit = jmvcore::Group,
    active = list(
        instructions = function() private$.items[["instructions"]],
        table = function() private$.items[["table"]],
        plot = function() private$.items[["plot"]],
        plot1 = function() private$.items[["plot1"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Concordance Correlation",
                refs="seolmatrix")
            self$add(jmvcore::Html$new(
                options=options,
                name="instructions",
                title="Instructions",
                visible=TRUE))
            self$add(jmvcore::Table$new(
                options=options,
                name="table",
                title="Estimated Correlation",
                rows=1,
                refs="epiR",
                clearWith=list(
                    "dep",
                    "covs"),
                columns=list(
                    list(
                        `name`="r", 
                        `title`="Concordance", 
                        `type`="number"),
                    list(
                        `name`="lower", 
                        `title`="Lower", 
                        `type`="number", 
                        `superTitle`="95% CI"),
                    list(
                        `name`="upper", 
                        `title`="Upper", 
                        `type`="number", 
                        `superTitle`="95% CI"))))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot",
                title="Concordance Plot",
                renderFun=".plot",
                visible="(ccp)",
                clearWith=list(
                    "dep",
                    "covs",
                    "width",
                    "height"),
                refs="epiR"))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot1",
                title="Bland-Altman Plot",
                renderFun=".plot1",
                visible="(bap)",
                clearWith=list(
                    "dep",
                    "covs",
                    "width1",
                    "height1"),
                refs="epiR"))}))

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

#' Concordance Correlation
#'
#' 
#' @param data .
#' @param dep .
#' @param covs .
#' @param cc .
#' @param ccp .
#' @param bap .
#' @param width .
#' @param height .
#' @param width1 .
#' @param height1 .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$instructions} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$table} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot1} \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$table$asDF}
#'
#' \code{as.data.frame(results$table)}
#'
#' @export
concordance <- function(
    data,
    dep,
    covs,
    cc = TRUE,
    ccp = FALSE,
    bap = FALSE,
    width = 500,
    height = 500,
    width1 = 500,
    height1 = 500) {

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

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


    options <- concordanceOptions$new(
        dep = dep,
        covs = covs,
        cc = cc,
        ccp = ccp,
        bap = bap,
        width = width,
        height = height,
        width1 = width1,
        height1 = height1)

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

    analysis$run()

    analysis$results
}
hyunsooseol/seolmatrix documentation built on July 25, 2024, 4:42 a.m.