R/manyttestsis.h.R

Defines functions manyttestsIS

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

manyttestsISOptions <- if (requireNamespace('jmvcore')) R6::R6Class(
    "manyttestsISOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            dep = NULL,
            groups = NULL,
            corMethod = "holm",
            hypothesis = "different",
            n = FALSE,
            meanDiff = FALSE,
            ci = FALSE,
            ciWidth = 95,
            effectSize = FALSE,
            ciES = FALSE,
            ciWidthES = 95,
            flag = FALSE, ...) {

            super$initialize(
                package='manytee',
                name='manyttestsIS',
                requiresData=TRUE,
                ...)

            private$..dep <- jmvcore::OptionVariable$new(
                "dep",
                dep,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"),
                rejectInf=FALSE)
            private$..groups <- jmvcore::OptionVariables$new(
                "groups",
                groups,
                suggested=list(
                    "nominal",
                    "ordinal"),
                permitted=list(
                    "factor"))
            private$..corMethod <- jmvcore::OptionList$new(
                "corMethod",
                corMethod,
                options=list(
                    "none",
                    "holm",
                    "hochberg",
                    "hommel",
                    "bonferroni",
                    "BH",
                    "BY"),
                default="holm")
            private$..hypothesis <- jmvcore::OptionList$new(
                "hypothesis",
                hypothesis,
                options=list(
                    "different",
                    "oneGreater",
                    "twoGreater"),
                default="different")
            private$..n <- jmvcore::OptionBool$new(
                "n",
                n,
                default=FALSE)
            private$..meanDiff <- jmvcore::OptionBool$new(
                "meanDiff",
                meanDiff,
                default=FALSE)
            private$..ci <- jmvcore::OptionBool$new(
                "ci",
                ci,
                default=FALSE)
            private$..ciWidth <- jmvcore::OptionNumber$new(
                "ciWidth",
                ciWidth,
                min=50,
                max=99.9,
                default=95)
            private$..effectSize <- jmvcore::OptionBool$new(
                "effectSize",
                effectSize,
                default=FALSE)
            private$..ciES <- jmvcore::OptionBool$new(
                "ciES",
                ciES,
                default=FALSE)
            private$..ciWidthES <- jmvcore::OptionNumber$new(
                "ciWidthES",
                ciWidthES,
                min=50,
                max=99.9,
                default=95)
            private$..flag <- jmvcore::OptionBool$new(
                "flag",
                flag,
                default=FALSE)

            self$.addOption(private$..dep)
            self$.addOption(private$..groups)
            self$.addOption(private$..corMethod)
            self$.addOption(private$..hypothesis)
            self$.addOption(private$..n)
            self$.addOption(private$..meanDiff)
            self$.addOption(private$..ci)
            self$.addOption(private$..ciWidth)
            self$.addOption(private$..effectSize)
            self$.addOption(private$..ciES)
            self$.addOption(private$..ciWidthES)
            self$.addOption(private$..flag)
        }),
    active = list(
        dep = function() private$..dep$value,
        groups = function() private$..groups$value,
        corMethod = function() private$..corMethod$value,
        hypothesis = function() private$..hypothesis$value,
        n = function() private$..n$value,
        meanDiff = function() private$..meanDiff$value,
        ci = function() private$..ci$value,
        ciWidth = function() private$..ciWidth$value,
        effectSize = function() private$..effectSize$value,
        ciES = function() private$..ciES$value,
        ciWidthES = function() private$..ciWidthES$value,
        flag = function() private$..flag$value),
    private = list(
        ..dep = NA,
        ..groups = NA,
        ..corMethod = NA,
        ..hypothesis = NA,
        ..n = NA,
        ..meanDiff = NA,
        ..ci = NA,
        ..ciWidth = NA,
        ..effectSize = NA,
        ..ciES = NA,
        ..ciWidthES = NA,
        ..flag = NA)
)

manyttestsISResults <- if (requireNamespace('jmvcore')) R6::R6Class(
    inherit = jmvcore::Group,
    active = list(
        tests = function() private$.items[["tests"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Pairwise T-Tests (Independent)")
            self$add(jmvcore::Table$new(
                options=options,
                name="tests",
                title="`Pairwise T-Tests - ${dep}`",
                columns=list(),
                clearWith=list(
                    "dep",
                    "groups",
                    "corMethod",
                    "ciWidth",
                    "ciWidthES")))}))

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

#' Pairwise T-Tests (Independent)
#'
#' The manyttestsIS function is used to perform t-tests for all possible 
#' combinations of (sub)groups of one or more grouping variables while 
#' being able to add a multiple testing correction for the p-values.
#' 
#'
#' @examples
#' data('ToothGrowth')
#'
#' manyttestsIS(data = ToothGrowth, dep = 'len', groups = 'dose')
#'
#' #
#' #  PAIRWISE T-TESTS (INDEPENDENT)
#' #
#' #  Pairwise T-Tests - len
#' #  --------------------------------------------
#' #  dose    dose    t         df      p-holm
#' #  --------------------------------------------
#' #  0.5     1        -6.48    38.0    < .001
#' #          2       -11.80    38.0    < .001
#' #  1       2        -4.90    38.0    < .001
#' #  --------------------------------------------
#' #  Note. Holm corrected p-value
#' #
#'
#' @param data the data as a data frame
#' @param dep the dependent variable
#' @param groups the grouping variables specifying the groups
#' @param corMethod \code{'none'}, \code{'holm'} (default), \code{'hochberg'},
#'   \code{'hommel'}, \code{'bonferroni'},  \code{'BH'}, or \code{'BY'}, the
#'   p-value correction method that is used; No  correction, Holm (1979),
#'   Hochberg (1988), Hommel (1988), Benjamini &  Hochberg (1995), and Benjamini
#'   & Yekutieli (2001) respectively
#' @param hypothesis \code{'different'} (default), \code{'oneGreater'} or
#'   \code{'twoGreater'}, the alternative hypothesis; group 1 different to group
#'   2, group 1 greater than group 2, and group 2 greater than group 1
#'   respectively
#' @param n \code{TRUE} or \code{FALSE} (default), provide the sample size of
#'   both groups
#' @param meanDiff \code{TRUE} or \code{FALSE} (default), provide means and
#'   standard errors
#' @param ci \code{TRUE} or \code{FALSE} (default), provide confidence
#'   intervals
#' @param ciWidth a number between 50 and 99.9 (default: 95), the width of
#'   confidence intervals
#' @param effectSize \code{TRUE} or \code{FALSE} (default), provide effect
#'   sizes
#' @param ciES \code{TRUE} or \code{FALSE} (default), provide confidence
#'   intervals for the effect-sizes
#' @param ciWidthES a number between 50 and 99.9 (default: 95), the width of
#'   confidence intervals for the effect sizes
#' @param flag \code{TRUE} or \code{FALSE} (default), flag significant tests
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$tests} \tab \tab \tab \tab \tab a table \cr
#' }
#'
#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example:
#'
#' \code{results$tests$asDF}
#'
#' \code{as.data.frame(results$tests)}
#'
#' @export
manyttestsIS <- function(
    data,
    dep,
    groups,
    corMethod = "holm",
    hypothesis = "different",
    n = FALSE,
    meanDiff = FALSE,
    ci = FALSE,
    ciWidth = 95,
    effectSize = FALSE,
    ciES = FALSE,
    ciWidthES = 95,
    flag = FALSE) {

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

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

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

    options <- manyttestsISOptions$new(
        dep = dep,
        groups = groups,
        corMethod = corMethod,
        hypothesis = hypothesis,
        n = n,
        meanDiff = meanDiff,
        ci = ci,
        ciWidth = ciWidth,
        effectSize = effectSize,
        ciES = ciES,
        ciWidthES = ciWidthES,
        flag = flag)

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

    analysis$run()

    analysis$results
}
raviselker/manytee documentation built on June 14, 2020, 2:09 p.m.