R/cor.h.R

Defines functions cor

Documented in cor

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

corOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "corOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            vars = NULL,
            type = "pearson",
            method = "ward.D",
            k = 2,
            size = 3,
            plot = FALSE,
            horiz = FALSE,
            plot1 = FALSE,
            poly = FALSE,
            plot2 = FALSE,
            plot3 = FALSE,
            horiz1 = FALSE,
            width = 500,
            height = 500,
            width3 = 500,
            height3 = 500,
            width4 = 500,
            height4 = 500,
            width5 = 500,
            height5 = 500, ...) {

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

            private$..vars <- jmvcore::OptionVariables$new(
                "vars",
                vars,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..type <- jmvcore::OptionList$new(
                "type",
                type,
                options=list(
                    "pearson",
                    "spearman"),
                default="pearson")
            private$..method <- jmvcore::OptionList$new(
                "method",
                method,
                options=list(
                    "none",
                    "ward.D",
                    "ward.D2",
                    "single",
                    "complete",
                    "average",
                    "mcquitty",
                    "median",
                    "centroid"),
                default="ward.D")
            private$..k <- jmvcore::OptionInteger$new(
                "k",
                k,
                min=1,
                default=2)
            private$..size <- jmvcore::OptionInteger$new(
                "size",
                size,
                default=3)
            private$..plot <- jmvcore::OptionBool$new(
                "plot",
                plot,
                default=FALSE)
            private$..horiz <- jmvcore::OptionBool$new(
                "horiz",
                horiz,
                default=FALSE)
            private$..plot1 <- jmvcore::OptionBool$new(
                "plot1",
                plot1,
                default=FALSE)
            private$..poly <- jmvcore::OptionBool$new(
                "poly",
                poly,
                default=FALSE)
            private$..plot2 <- jmvcore::OptionBool$new(
                "plot2",
                plot2,
                default=FALSE)
            private$..plot3 <- jmvcore::OptionBool$new(
                "plot3",
                plot3,
                default=FALSE)
            private$..horiz1 <- jmvcore::OptionBool$new(
                "horiz1",
                horiz1,
                default=FALSE)
            private$..width <- jmvcore::OptionInteger$new(
                "width",
                width,
                default=500)
            private$..height <- jmvcore::OptionInteger$new(
                "height",
                height,
                default=500)
            private$..width3 <- jmvcore::OptionInteger$new(
                "width3",
                width3,
                default=500)
            private$..height3 <- jmvcore::OptionInteger$new(
                "height3",
                height3,
                default=500)
            private$..width4 <- jmvcore::OptionInteger$new(
                "width4",
                width4,
                default=500)
            private$..height4 <- jmvcore::OptionInteger$new(
                "height4",
                height4,
                default=500)
            private$..width5 <- jmvcore::OptionInteger$new(
                "width5",
                width5,
                default=500)
            private$..height5 <- jmvcore::OptionInteger$new(
                "height5",
                height5,
                default=500)

            self$.addOption(private$..vars)
            self$.addOption(private$..type)
            self$.addOption(private$..method)
            self$.addOption(private$..k)
            self$.addOption(private$..size)
            self$.addOption(private$..plot)
            self$.addOption(private$..horiz)
            self$.addOption(private$..plot1)
            self$.addOption(private$..poly)
            self$.addOption(private$..plot2)
            self$.addOption(private$..plot3)
            self$.addOption(private$..horiz1)
            self$.addOption(private$..width)
            self$.addOption(private$..height)
            self$.addOption(private$..width3)
            self$.addOption(private$..height3)
            self$.addOption(private$..width4)
            self$.addOption(private$..height4)
            self$.addOption(private$..width5)
            self$.addOption(private$..height5)
        }),
    active = list(
        vars = function() private$..vars$value,
        type = function() private$..type$value,
        method = function() private$..method$value,
        k = function() private$..k$value,
        size = function() private$..size$value,
        plot = function() private$..plot$value,
        horiz = function() private$..horiz$value,
        plot1 = function() private$..plot1$value,
        poly = function() private$..poly$value,
        plot2 = function() private$..plot2$value,
        plot3 = function() private$..plot3$value,
        horiz1 = function() private$..horiz1$value,
        width = function() private$..width$value,
        height = function() private$..height$value,
        width3 = function() private$..width3$value,
        height3 = function() private$..height3$value,
        width4 = function() private$..width4$value,
        height4 = function() private$..height4$value,
        width5 = function() private$..width5$value,
        height5 = function() private$..height5$value),
    private = list(
        ..vars = NA,
        ..type = NA,
        ..method = NA,
        ..k = NA,
        ..size = NA,
        ..plot = NA,
        ..horiz = NA,
        ..plot1 = NA,
        ..poly = NA,
        ..plot2 = NA,
        ..plot3 = NA,
        ..horiz1 = NA,
        ..width = NA,
        ..height = NA,
        ..width3 = NA,
        ..height3 = NA,
        ..width4 = NA,
        ..height4 = NA,
        ..width5 = NA,
        ..height5 = NA)
)

corResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "corResults",
    inherit = jmvcore::Group,
    active = list(
        instructions = function() private$.items[["instructions"]],
        plot = function() private$.items[["plot"]],
        plot1 = function() private$.items[["plot1"]],
        plot2 = function() private$.items[["plot2"]],
        plot3 = function() private$.items[["plot3"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Correlation Structure",
                refs="seolmatrix")
            self$add(jmvcore::Html$new(
                options=options,
                name="instructions",
                title="Instructions",
                visible=TRUE))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot",
                title="Heatmap",
                visible="(plot)",
                refs="ShinyItemAnalysis",
                renderFun=".plot",
                clearWith=list(
                    "vars",
                    "k",
                    "type",
                    "method",
                    "size",
                    "horiz",
                    "width",
                    "height")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot1",
                title="Dendrogram",
                visible="(plot1)",
                renderFun=".plot1",
                clearWith=list(
                    "vars",
                    "k",
                    "type",
                    "method",
                    "size",
                    "horiz",
                    "width5",
                    "height5")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot2",
                title="Polychoric Heatmap",
                requiresData=TRUE,
                visible="(plot2)",
                renderFun=".plot2",
                clearWith=list(
                    "vars",
                    "k",
                    "type",
                    "method",
                    "size",
                    "horiz",
                    "horiz1",
                    "width4",
                    "height4")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot3",
                title="Polychoric Dendrogram",
                requiresData=TRUE,
                visible="(plot3)",
                renderFun=".plot3",
                clearWith=list(
                    "vars",
                    "k",
                    "type",
                    "method",
                    "size",
                    "horiz1",
                    "width3",
                    "height3")))}))

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

#' Correlation Structure
#'
#' 
#' @param data The data as a data frame.
#' @param vars .
#' @param type .
#' @param method .
#' @param k .
#' @param size .
#' @param plot .
#' @param horiz .
#' @param plot1 .
#' @param poly .
#' @param plot2 .
#' @param plot3 .
#' @param horiz1 .
#' @param width .
#' @param height .
#' @param width3 .
#' @param height3 .
#' @param width4 .
#' @param height4 .
#' @param width5 .
#' @param height5 .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$instructions} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot1} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot2} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot3} \tab \tab \tab \tab \tab an image \cr
#' }
#'
#' @export
cor <- function(
    data,
    vars,
    type = "pearson",
    method = "ward.D",
    k = 2,
    size = 3,
    plot = FALSE,
    horiz = FALSE,
    plot1 = FALSE,
    poly = FALSE,
    plot2 = FALSE,
    plot3 = FALSE,
    horiz1 = FALSE,
    width = 500,
    height = 500,
    width3 = 500,
    height3 = 500,
    width4 = 500,
    height4 = 500,
    width5 = 500,
    height5 = 500) {

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

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


    options <- corOptions$new(
        vars = vars,
        type = type,
        method = method,
        k = k,
        size = size,
        plot = plot,
        horiz = horiz,
        plot1 = plot1,
        poly = poly,
        plot2 = plot2,
        plot3 = plot3,
        horiz1 = horiz1,
        width = width,
        height = height,
        width3 = width3,
        height3 = height3,
        width4 = width4,
        height4 = height4,
        width5 = width5,
        height5 = height5)

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

    analysis$run()

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