R/catdes.h.R

Defines functions catdes

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

catdesOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "catdesOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            vartochar = NULL,
            descbyvar = NULL,
            tuto = TRUE,
            threshold = 5, ...) {

            super$initialize(
                package="MEDA",
                name="catdes",
                requiresData=TRUE,
                ...)

            private$..vartochar <- jmvcore::OptionVariable$new(
                "vartochar",
                vartochar,
                suggested=list(
                    "continuous",
                    "nominal"),
                permitted=list(
                    "numeric",
                    "factor"))
            private$..descbyvar <- jmvcore::OptionVariables$new(
                "descbyvar",
                descbyvar,
                suggested=list(
                    "continuous",
                    "nominal"),
                permitted=list(
                    "numeric",
                    "factor"))
            private$..tuto <- jmvcore::OptionBool$new(
                "tuto",
                tuto,
                default=TRUE)
            private$..threshold <- jmvcore::OptionNumber$new(
                "threshold",
                threshold,
                default=5)

            self$.addOption(private$..vartochar)
            self$.addOption(private$..descbyvar)
            self$.addOption(private$..tuto)
            self$.addOption(private$..threshold)
        }),
    active = list(
        vartochar = function() private$..vartochar$value,
        descbyvar = function() private$..descbyvar$value,
        tuto = function() private$..tuto$value,
        threshold = function() private$..threshold$value),
    private = list(
        ..vartochar = NA,
        ..descbyvar = NA,
        ..tuto = NA,
        ..threshold = NA)
)

catdesResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "catdesResults",
    inherit = jmvcore::Group,
    active = list(
        instructions = function() private$.items[["instructions"]],
        chigroup = function() private$.items[["chigroup"]],
        categgroup = function() private$.items[["categgroup"]],
        qtvargroup = function() private$.items[["qtvargroup"]],
        qtgroup = function() private$.items[["qtgroup"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Results of the Variable Description",
                refs=list(
                    "factominer",
                    "explo"))
            self$add(jmvcore::Html$new(
                options=options,
                name="instructions",
                title="Instructions",
                visible="(tuto)"))
            self$add(R6::R6Class(
                inherit = jmvcore::Group,
                active = list(
                    chi = function() private$.items[["chi"]]),
                private = list(),
                public=list(
                    initialize=function(options) {
                        super$initialize(
                            options=options,
                            name="chigroup",
                            title="Chi-Squared Test")
                        self$add(jmvcore::Table$new(
                            options=options,
                            name="chi",
                            title="Link Between the 'Cluster' Variable and the Categorical Variables",
                            columns=list(
                                list(
                                    `name`="varchi", 
                                    `title`="", 
                                    `type`="text"),
                                list(
                                    `name`="chipv", 
                                    `title`="p", 
                                    `type`="number", 
                                    `format`="zto,pvalue"),
                                list(
                                    `name`="df", 
                                    `title`="df", 
                                    `type`="integer"))))}))$new(options=options))
            self$add(R6::R6Class(
                inherit = jmvcore::Group,
                active = list(
                    categquali = function() private$.items[["categquali"]],
                    qualir2 = function() private$.items[["qualir2"]],
                    categquanti = function() private$.items[["categquanti"]]),
                private = list(),
                public=list(
                    initialize=function(options) {
                        super$initialize(
                            options=options,
                            name="categgroup",
                            title="Description by the Categorical Variables")
                        self$add(jmvcore::Table$new(
                            options=options,
                            name="categquali",
                            title="Description of Each 'Cluster' by the Categories",
                            columns=list(
                                list(
                                    `name`="varcateg", 
                                    `title`="", 
                                    `type`="text", 
                                    `combineBelow`=TRUE),
                                list(
                                    `name`="vardesccateg", 
                                    `title`="Category", 
                                    `type`="text"),
                                list(
                                    `name`="clamod", 
                                    `title`="Cla/Mod", 
                                    `type`="number"),
                                list(
                                    `name`="modcla", 
                                    `title`="Mod/Cla", 
                                    `type`="number"),
                                list(
                                    `name`="global", 
                                    `title`="Global", 
                                    `type`="number"),
                                list(
                                    `name`="categpv", 
                                    `title`="p", 
                                    `type`="number", 
                                    `format`="zto,pvalue"),
                                list(
                                    `name`="vtest", 
                                    `title`="Vtest", 
                                    `type`="number"))))
                        self$add(jmvcore::Table$new(
                            options=options,
                            name="qualir2",
                            title="Link with the Qualitative Variables",
                            columns=list(
                                list(
                                    `name`="varr2", 
                                    `title`="", 
                                    `type`="text"),
                                list(
                                    `name`="r2", 
                                    `title`="R\u00B2", 
                                    `type`="number", 
                                    `format`="zto"),
                                list(
                                    `name`="r2pvalue", 
                                    `title`="p", 
                                    `type`="number", 
                                    `format`="zto,pvalue"))))
                        self$add(jmvcore::Table$new(
                            options=options,
                            name="categquanti",
                            title="Description of the Quantitative Variable by the Categories",
                            columns=list(
                                list(
                                    `name`="varcateg", 
                                    `title`="", 
                                    `type`="text", 
                                    `combineBelow`=TRUE),
                                list(
                                    `name`="vardesccateg", 
                                    `title`="Category", 
                                    `type`="text"),
                                list(
                                    `name`="estimate", 
                                    `title`="Estimate", 
                                    `type`="number"),
                                list(
                                    `name`="categpv", 
                                    `title`="p", 
                                    `type`="number", 
                                    `format`="zto,pvalue"))))}))$new(options=options))
            self$add(R6::R6Class(
                inherit = jmvcore::Group,
                active = list(
                    qtvar = function() private$.items[["qtvar"]]),
                private = list(),
                public=list(
                    initialize=function(options) {
                        super$initialize(
                            options=options,
                            name="qtvargroup",
                            title="Global Description by the Quantitative Variables")
                        self$add(jmvcore::Table$new(
                            options=options,
                            name="qtvar",
                            title="Link Between the 'Cluster' Variable and the Quantitative Variables",
                            columns=list(
                                list(
                                    `name`="varqtvar", 
                                    `title`="", 
                                    `type`="text"),
                                list(
                                    `name`="scc", 
                                    `title`="Square correlation coefficient", 
                                    `type`="number"),
                                list(
                                    `name`="qtvarpv", 
                                    `title`="p", 
                                    `type`="number", 
                                    `format`="zto,pvalue"))))}))$new(options=options))
            self$add(R6::R6Class(
                inherit = jmvcore::Group,
                active = list(
                    qt = function() private$.items[["qt"]],
                    qtcor = function() private$.items[["qtcor"]]),
                private = list(),
                public=list(
                    initialize=function(options) {
                        super$initialize(
                            options=options,
                            name="qtgroup",
                            title="Description by the Quantitative Variables")
                        self$add(jmvcore::Table$new(
                            options=options,
                            name="qt",
                            title="Description of Each 'Cluster' by the Quantative Variables",
                            columns=list(
                                list(
                                    `name`="varqt", 
                                    `title`="", 
                                    `type`="text"),
                                list(
                                    `name`="vardescqt", 
                                    `title`="Variable", 
                                    `type`="text"),
                                list(
                                    `name`="vtestqt", 
                                    `title`="Vtest", 
                                    `type`="number"),
                                list(
                                    `name`="meancateg", 
                                    `title`="Mean in category", 
                                    `type`="number"),
                                list(
                                    `name`="overallmean", 
                                    `title`="Overall mean", 
                                    `type`="number"),
                                list(
                                    `name`="sdcateg", 
                                    `title`="sd in category", 
                                    `type`="number"),
                                list(
                                    `name`="overallsd", 
                                    `title`="Overall sd", 
                                    `type`="number"),
                                list(
                                    `name`="qtpv", 
                                    `title`="p", 
                                    `type`="number", 
                                    `format`="zto,pvalue"))))
                        self$add(jmvcore::Table$new(
                            options=options,
                            name="qtcor",
                            title="Link with the Quantitative Variables",
                            columns=list(
                                list(
                                    `name`="varcor", 
                                    `title`="", 
                                    `type`="text"),
                                list(
                                    `name`="cor", 
                                    `title`="Correlation", 
                                    `type`="number"),
                                list(
                                    `name`="corpvalue", 
                                    `title`="p", 
                                    `type`="number", 
                                    `format`="zto,pvalue"))))}))$new(options=options))}))

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

#' Variable Described by Categorical / Quantitative Data
#'
#' 
#' @param data .
#' @param vartochar .
#' @param descbyvar .
#' @param tuto .
#' @param threshold .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$instructions} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$chigroup$chi} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$categgroup$categquali} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$categgroup$qualir2} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$categgroup$categquanti} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$qtvargroup$qtvar} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$qtgroup$qt} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$qtgroup$qtcor} \tab \tab \tab \tab \tab a table \cr
#' }
#'
#' @export
catdes <- function(
    data,
    vartochar,
    descbyvar,
    tuto = TRUE,
    threshold = 5) {

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

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


    options <- catdesOptions$new(
        vartochar = vartochar,
        descbyvar = descbyvar,
        tuto = tuto,
        threshold = threshold)

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

    analysis$run()

    analysis$results
}
Sebastien-Le/MEDA documentation built on Dec. 15, 2024, 12:58 a.m.