sbalci/ClinicoPathJamoviModule

View on GitHub
R/timeinterval.h.R

Summary

Maintainability
Test Coverage

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

timeintervalOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "timeintervalOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            explanatory = NULL,
            overalltime = NULL,
            outcome = NULL,
            outcomeLevel = NULL, ...) {

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

            private$..explanatory <- jmvcore::OptionVariables$new(
                "explanatory",
                explanatory,
                suggested=list(
                    "ordinal",
                    "nominal"),
                permitted=list(
                    "factor"))
            private$..overalltime <- jmvcore::OptionVariable$new(
                "overalltime",
                overalltime,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..outcome <- jmvcore::OptionVariable$new(
                "outcome",
                outcome)
            private$..outcomeLevel <- jmvcore::OptionLevel$new(
                "outcomeLevel",
                outcomeLevel,
                variable="(outcome)")

            self$.addOption(private$..explanatory)
            self$.addOption(private$..overalltime)
            self$.addOption(private$..outcome)
            self$.addOption(private$..outcomeLevel)
        }),
    active = list(
        explanatory = function() private$..explanatory$value,
        overalltime = function() private$..overalltime$value,
        outcome = function() private$..outcome$value,
        outcomeLevel = function() private$..outcomeLevel$value),
    private = list(
        ..explanatory = NA,
        ..overalltime = NA,
        ..outcome = NA,
        ..outcomeLevel = NA)
)

timeintervalResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "timeintervalResults",
    inherit = jmvcore::Group,
    active = list(
        text1 = function() private$.items[["text1"]],
        text1table = function() private$.items[["text1table"]],
        text1html = function() private$.items[["text1html"]],
        text2 = function() private$.items[["text2"]],
        medianTable = function() private$.items[["medianTable"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Time Interval",
                refs=list(
                    "ClinicoPathJamoviModule"))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="text1",
                title="denemeler"))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="text1table",
                title="fit"))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="text1html",
                title="fit"))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="text2",
                title="Median Survival Summary and Table"))
            self$add(jmvcore::Table$new(
                options=options,
                name="medianTable",
                title="Median Survival Table",
                rows=0,
                columns=list(
                    list(
                        `name`="factor", 
                        `title`="Levels", 
                        `type`="text"),
                    list(
                        `name`="records", 
                        `title`="Records", 
                        `type`="number"),
                    list(
                        `name`="events", 
                        `title`="Events", 
                        `type`="integer"),
                    list(
                        `name`="rmean", 
                        `title`="rmean", 
                        `type`="number"),
                    list(
                        `name`="se_rmean", 
                        `title`="se_rmean", 
                        `type`="number"),
                    list(
                        `name`="median", 
                        `title`="Median", 
                        `type`="number"),
                    list(
                        `name`="x0_95lcl", 
                        `title`="Lower", 
                        `superTitle`="95% Confidence Interval", 
                        `type`="number"),
                    list(
                        `name`="x0_95ucl", 
                        `title`="Upper", 
                        `superTitle`="95% Confidence Interval", 
                        `type`="number"))))}))

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

#' Time Interval
#'
#' 
#' @param data The data as a data frame.
#' @param explanatory .
#' @param overalltime .
#' @param outcome .
#' @param outcomeLevel .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$text1} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$text1table} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$text1html} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$text2} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$medianTable} \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$medianTable$asDF}
#'
#' \code{as.data.frame(results$medianTable)}
#'
#' @export
timeinterval <- function(
    data,
    explanatory,
    overalltime,
    outcome,
    outcomeLevel) {

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

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

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

    options <- timeintervalOptions$new(
        explanatory = explanatory,
        overalltime = overalltime,
        outcome = outcome,
        outcomeLevel = outcomeLevel)

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

    analysis$run()

    analysis$results
}