R/jjhistostats.h.R

Defines functions jjhistostats

Documented in jjhistostats

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

jjhistostatsOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "jjhistostatsOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            dep = NULL,
            grvar = NULL,
            typestatistics = "parametric",
            centralityline = TRUE,
            changebinwidth = FALSE,
            binwidth = 1.1,
            resultssubtitle = TRUE,
            normalcurve = FALSE, ...) {

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

            private$..dep <- jmvcore::OptionVariables$new(
                "dep",
                dep,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..grvar <- jmvcore::OptionVariable$new(
                "grvar",
                grvar,
                suggested=list(
                    "ordinal",
                    "nominal"),
                permitted=list(
                    "factor"))
            private$..typestatistics <- jmvcore::OptionList$new(
                "typestatistics",
                typestatistics,
                options=list(
                    "parametric",
                    "nonparametric",
                    "robust",
                    "bayes"),
                default="parametric")
            private$..centralityline <- jmvcore::OptionBool$new(
                "centralityline",
                centralityline,
                default=TRUE)
            private$..changebinwidth <- jmvcore::OptionBool$new(
                "changebinwidth",
                changebinwidth,
                default=FALSE)
            private$..binwidth <- jmvcore::OptionNumber$new(
                "binwidth",
                binwidth,
                default=1.1)
            private$..resultssubtitle <- jmvcore::OptionBool$new(
                "resultssubtitle",
                resultssubtitle,
                default=TRUE)
            private$..normalcurve <- jmvcore::OptionBool$new(
                "normalcurve",
                normalcurve,
                default=FALSE)

            self$.addOption(private$..dep)
            self$.addOption(private$..grvar)
            self$.addOption(private$..typestatistics)
            self$.addOption(private$..centralityline)
            self$.addOption(private$..changebinwidth)
            self$.addOption(private$..binwidth)
            self$.addOption(private$..resultssubtitle)
            self$.addOption(private$..normalcurve)
        }),
    active = list(
        dep = function() private$..dep$value,
        grvar = function() private$..grvar$value,
        typestatistics = function() private$..typestatistics$value,
        centralityline = function() private$..centralityline$value,
        changebinwidth = function() private$..changebinwidth$value,
        binwidth = function() private$..binwidth$value,
        resultssubtitle = function() private$..resultssubtitle$value,
        normalcurve = function() private$..normalcurve$value),
    private = list(
        ..dep = NA,
        ..grvar = NA,
        ..typestatistics = NA,
        ..centralityline = NA,
        ..changebinwidth = NA,
        ..binwidth = NA,
        ..resultssubtitle = NA,
        ..normalcurve = NA)
)

jjhistostatsResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "jjhistostatsResults",
    inherit = jmvcore::Group,
    active = list(
        todo = function() private$.items[["todo"]],
        plot2 = function() private$.items[["plot2"]],
        plot = function() private$.items[["plot"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Histogram",
                refs=list(
                    "ggplot2",
                    "ggstatsplot",
                    "ClinicoPathJamoviModule"),
                clearWith=list(
                    "*"))
            self$add(jmvcore::Html$new(
                options=options,
                name="todo",
                title="To Do"))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot2",
                title="`Histogram Splitted by {grvar}`",
                renderFun=".plot2",
                requiresData=TRUE,
                visible="(grvar)"))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot",
                title="Histogram",
                renderFun=".plot",
                requiresData=TRUE))}))

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

#' Histogram
#'
#' 'Wrapper Function for ggstatsplot::gghistostats and
#' ggstatsplot::grouped_gghistostats to generate Histogram.'
#' 
#'
#' @examples
#' \donttest{
#' # example will be added
#'}
#' @param data The data as a data frame.
#' @param dep .
#' @param grvar .
#' @param typestatistics .
#' @param centralityline .
#' @param changebinwidth .
#' @param binwidth .
#' @param resultssubtitle .
#' @param normalcurve .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$todo} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$plot2} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#' }
#'
#' @export
jjhistostats <- function(
    data,
    dep,
    grvar,
    typestatistics = "parametric",
    centralityline = TRUE,
    changebinwidth = FALSE,
    binwidth = 1.1,
    resultssubtitle = TRUE,
    normalcurve = FALSE) {

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

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

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

    options <- jjhistostatsOptions$new(
        dep = dep,
        grvar = grvar,
        typestatistics = typestatistics,
        centralityline = centralityline,
        changebinwidth = changebinwidth,
        binwidth = binwidth,
        resultssubtitle = resultssubtitle,
        normalcurve = normalcurve)

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

    analysis$run()

    analysis$results
}
sbalci/ClinicoPathJamoviModule documentation built on Feb. 25, 2025, 6:34 a.m.