R/multisurvival.h.R

Defines functions multisurvival

Documented in multisurvival

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

multisurvivalOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "multisurvivalOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            elapsedtime = NULL,
            tint = FALSE,
            dxdate = NULL,
            fudate = NULL,
            timetypedata = "ymd",
            timetypeoutput = "months",
            uselandmark = FALSE,
            landmark = 3,
            outcome = NULL,
            outcomeLevel = NULL,
            dod = NULL,
            dooc = NULL,
            awd = NULL,
            awod = NULL,
            analysistype = "overall",
            explanatory = NULL,
            contexpl = NULL,
            multievent = FALSE,
            hr = FALSE,
            sty = "t1",
            ph_cox = FALSE,
            km = FALSE,
            endplot = 60,
            byplot = 12,
            ci95 = FALSE,
            risktable = FALSE,
            censored = FALSE,
            medianline = "none",
            pplot = TRUE,
            cutp = "12, 36, 60",
            calculateRiskScore = FALSE,
            numRiskGroups = "four",
            plotRiskGroups = FALSE,
            ac = FALSE,
            adjexplanatory = NULL,
            ac_method = "average",
            showNomogram = FALSE,
            use_modelSelection = FALSE,
            modelSelection = "enter",
            selectionCriteria = "aic",
            pEntry = 0.05,
            pRemoval = 0.1,
            use_stratify = FALSE,
            stratvar = NULL,
            person_time = FALSE,
            time_intervals = "12, 36, 60",
            rate_multiplier = 100,
            use_tree = FALSE,
            min_node = 20,
            complexity = 0.01,
            max_depth = 5,
            show_terminal_nodes = TRUE, ...) {

            super$initialize(
                package="jsurvival",
                name="multisurvival",
                requiresData=TRUE,
                ...)

            private$..elapsedtime <- jmvcore::OptionVariable$new(
                "elapsedtime",
                elapsedtime,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..tint <- jmvcore::OptionBool$new(
                "tint",
                tint,
                default=FALSE)
            private$..dxdate <- jmvcore::OptionVariable$new(
                "dxdate",
                dxdate)
            private$..fudate <- jmvcore::OptionVariable$new(
                "fudate",
                fudate)
            private$..timetypedata <- jmvcore::OptionList$new(
                "timetypedata",
                timetypedata,
                options=list(
                    "ymdhms",
                    "ymd",
                    "ydm",
                    "mdy",
                    "myd",
                    "dmy",
                    "dym"),
                default="ymd")
            private$..timetypeoutput <- jmvcore::OptionList$new(
                "timetypeoutput",
                timetypeoutput,
                options=list(
                    "days",
                    "weeks",
                    "months",
                    "years"),
                default="months")
            private$..uselandmark <- jmvcore::OptionBool$new(
                "uselandmark",
                uselandmark,
                default=FALSE)
            private$..landmark <- jmvcore::OptionInteger$new(
                "landmark",
                landmark,
                default=3)
            private$..calculatedtime <- jmvcore::OptionOutput$new(
                "calculatedtime")
            private$..outcome <- jmvcore::OptionVariable$new(
                "outcome",
                outcome,
                suggested=list(
                    "ordinal",
                    "nominal",
                    "continuous"),
                permitted=list(
                    "factor",
                    "numeric"))
            private$..outcomeLevel <- jmvcore::OptionLevel$new(
                "outcomeLevel",
                outcomeLevel,
                variable="(outcome)")
            private$..dod <- jmvcore::OptionLevel$new(
                "dod",
                dod,
                variable="(outcome)",
                allowNone=TRUE)
            private$..dooc <- jmvcore::OptionLevel$new(
                "dooc",
                dooc,
                variable="(outcome)",
                allowNone=TRUE)
            private$..awd <- jmvcore::OptionLevel$new(
                "awd",
                awd,
                variable="(outcome)",
                allowNone=TRUE)
            private$..awod <- jmvcore::OptionLevel$new(
                "awod",
                awod,
                variable="(outcome)",
                allowNone=TRUE)
            private$..analysistype <- jmvcore::OptionList$new(
                "analysistype",
                analysistype,
                options=list(
                    "overall",
                    "cause",
                    "compete"),
                default="overall")
            private$..outcomeredefined <- jmvcore::OptionOutput$new(
                "outcomeredefined")
            private$..explanatory <- jmvcore::OptionVariables$new(
                "explanatory",
                explanatory,
                suggested=list(
                    "ordinal",
                    "nominal"),
                permitted=list(
                    "factor"))
            private$..contexpl <- jmvcore::OptionVariables$new(
                "contexpl",
                contexpl,
                suggested=list(
                    "continuous"),
                permitted=list(
                    "numeric"))
            private$..multievent <- jmvcore::OptionBool$new(
                "multievent",
                multievent,
                default=FALSE)
            private$..hr <- jmvcore::OptionBool$new(
                "hr",
                hr,
                default=FALSE)
            private$..sty <- jmvcore::OptionList$new(
                "sty",
                sty,
                options=list(
                    "t1",
                    "t3"),
                default="t1")
            private$..ph_cox <- jmvcore::OptionBool$new(
                "ph_cox",
                ph_cox,
                default=FALSE)
            private$..km <- jmvcore::OptionBool$new(
                "km",
                km,
                default=FALSE)
            private$..endplot <- jmvcore::OptionInteger$new(
                "endplot",
                endplot,
                default=60)
            private$..byplot <- jmvcore::OptionInteger$new(
                "byplot",
                byplot,
                default=12)
            private$..ci95 <- jmvcore::OptionBool$new(
                "ci95",
                ci95,
                default=FALSE)
            private$..risktable <- jmvcore::OptionBool$new(
                "risktable",
                risktable,
                default=FALSE)
            private$..censored <- jmvcore::OptionBool$new(
                "censored",
                censored,
                default=FALSE)
            private$..medianline <- jmvcore::OptionList$new(
                "medianline",
                medianline,
                options=list(
                    "none",
                    "h",
                    "v",
                    "hv"),
                default="none")
            private$..pplot <- jmvcore::OptionBool$new(
                "pplot",
                pplot,
                default=TRUE)
            private$..cutp <- jmvcore::OptionString$new(
                "cutp",
                cutp,
                default="12, 36, 60")
            private$..calculateRiskScore <- jmvcore::OptionBool$new(
                "calculateRiskScore",
                calculateRiskScore,
                default=FALSE)
            private$..numRiskGroups <- jmvcore::OptionList$new(
                "numRiskGroups",
                numRiskGroups,
                options=list(
                    "two",
                    "three",
                    "four"),
                default="four")
            private$..plotRiskGroups <- jmvcore::OptionBool$new(
                "plotRiskGroups",
                plotRiskGroups,
                default=FALSE)
            private$..addRiskScore <- jmvcore::OptionOutput$new(
                "addRiskScore")
            private$..addRiskGroup <- jmvcore::OptionOutput$new(
                "addRiskGroup")
            private$..ac <- jmvcore::OptionBool$new(
                "ac",
                ac,
                default=FALSE)
            private$..adjexplanatory <- jmvcore::OptionVariable$new(
                "adjexplanatory",
                adjexplanatory,
                suggested=list(
                    "ordinal",
                    "nominal"),
                permitted=list(
                    "factor"))
            private$..ac_method <- jmvcore::OptionList$new(
                "ac_method",
                ac_method,
                options=list(
                    "average",
                    "conditional",
                    "single",
                    "marginal"),
                default="average")
            private$..showNomogram <- jmvcore::OptionBool$new(
                "showNomogram",
                showNomogram,
                default=FALSE)
            private$..use_modelSelection <- jmvcore::OptionBool$new(
                "use_modelSelection",
                use_modelSelection,
                default=FALSE)
            private$..modelSelection <- jmvcore::OptionList$new(
                "modelSelection",
                modelSelection,
                options=list(
                    "enter",
                    "forward",
                    "backward",
                    "both"),
                default="enter")
            private$..selectionCriteria <- jmvcore::OptionList$new(
                "selectionCriteria",
                selectionCriteria,
                options=list(
                    "aic",
                    "lrt"),
                default="aic")
            private$..pEntry <- jmvcore::OptionNumber$new(
                "pEntry",
                pEntry,
                min=0,
                max=1,
                default=0.05)
            private$..pRemoval <- jmvcore::OptionNumber$new(
                "pRemoval",
                pRemoval,
                min=0,
                max=1,
                default=0.1)
            private$..use_stratify <- jmvcore::OptionBool$new(
                "use_stratify",
                use_stratify,
                default=FALSE)
            private$..stratvar <- jmvcore::OptionVariables$new(
                "stratvar",
                stratvar,
                suggested=list(
                    "ordinal",
                    "nominal"),
                permitted=list(
                    "factor"))
            private$..person_time <- jmvcore::OptionBool$new(
                "person_time",
                person_time,
                default=FALSE)
            private$..time_intervals <- jmvcore::OptionString$new(
                "time_intervals",
                time_intervals,
                default="12, 36, 60")
            private$..rate_multiplier <- jmvcore::OptionInteger$new(
                "rate_multiplier",
                rate_multiplier,
                default=100)
            private$..use_tree <- jmvcore::OptionBool$new(
                "use_tree",
                use_tree,
                default=FALSE)
            private$..min_node <- jmvcore::OptionInteger$new(
                "min_node",
                min_node,
                min=5,
                max=100,
                default=20)
            private$..complexity <- jmvcore::OptionNumber$new(
                "complexity",
                complexity,
                min=0.001,
                max=0.1,
                default=0.01)
            private$..max_depth <- jmvcore::OptionInteger$new(
                "max_depth",
                max_depth,
                min=1,
                max=10,
                default=5)
            private$..show_terminal_nodes <- jmvcore::OptionBool$new(
                "show_terminal_nodes",
                show_terminal_nodes,
                default=TRUE)

            self$.addOption(private$..elapsedtime)
            self$.addOption(private$..tint)
            self$.addOption(private$..dxdate)
            self$.addOption(private$..fudate)
            self$.addOption(private$..timetypedata)
            self$.addOption(private$..timetypeoutput)
            self$.addOption(private$..uselandmark)
            self$.addOption(private$..landmark)
            self$.addOption(private$..calculatedtime)
            self$.addOption(private$..outcome)
            self$.addOption(private$..outcomeLevel)
            self$.addOption(private$..dod)
            self$.addOption(private$..dooc)
            self$.addOption(private$..awd)
            self$.addOption(private$..awod)
            self$.addOption(private$..analysistype)
            self$.addOption(private$..outcomeredefined)
            self$.addOption(private$..explanatory)
            self$.addOption(private$..contexpl)
            self$.addOption(private$..multievent)
            self$.addOption(private$..hr)
            self$.addOption(private$..sty)
            self$.addOption(private$..ph_cox)
            self$.addOption(private$..km)
            self$.addOption(private$..endplot)
            self$.addOption(private$..byplot)
            self$.addOption(private$..ci95)
            self$.addOption(private$..risktable)
            self$.addOption(private$..censored)
            self$.addOption(private$..medianline)
            self$.addOption(private$..pplot)
            self$.addOption(private$..cutp)
            self$.addOption(private$..calculateRiskScore)
            self$.addOption(private$..numRiskGroups)
            self$.addOption(private$..plotRiskGroups)
            self$.addOption(private$..addRiskScore)
            self$.addOption(private$..addRiskGroup)
            self$.addOption(private$..ac)
            self$.addOption(private$..adjexplanatory)
            self$.addOption(private$..ac_method)
            self$.addOption(private$..showNomogram)
            self$.addOption(private$..use_modelSelection)
            self$.addOption(private$..modelSelection)
            self$.addOption(private$..selectionCriteria)
            self$.addOption(private$..pEntry)
            self$.addOption(private$..pRemoval)
            self$.addOption(private$..use_stratify)
            self$.addOption(private$..stratvar)
            self$.addOption(private$..person_time)
            self$.addOption(private$..time_intervals)
            self$.addOption(private$..rate_multiplier)
            self$.addOption(private$..use_tree)
            self$.addOption(private$..min_node)
            self$.addOption(private$..complexity)
            self$.addOption(private$..max_depth)
            self$.addOption(private$..show_terminal_nodes)
        }),
    active = list(
        elapsedtime = function() private$..elapsedtime$value,
        tint = function() private$..tint$value,
        dxdate = function() private$..dxdate$value,
        fudate = function() private$..fudate$value,
        timetypedata = function() private$..timetypedata$value,
        timetypeoutput = function() private$..timetypeoutput$value,
        uselandmark = function() private$..uselandmark$value,
        landmark = function() private$..landmark$value,
        calculatedtime = function() private$..calculatedtime$value,
        outcome = function() private$..outcome$value,
        outcomeLevel = function() private$..outcomeLevel$value,
        dod = function() private$..dod$value,
        dooc = function() private$..dooc$value,
        awd = function() private$..awd$value,
        awod = function() private$..awod$value,
        analysistype = function() private$..analysistype$value,
        outcomeredefined = function() private$..outcomeredefined$value,
        explanatory = function() private$..explanatory$value,
        contexpl = function() private$..contexpl$value,
        multievent = function() private$..multievent$value,
        hr = function() private$..hr$value,
        sty = function() private$..sty$value,
        ph_cox = function() private$..ph_cox$value,
        km = function() private$..km$value,
        endplot = function() private$..endplot$value,
        byplot = function() private$..byplot$value,
        ci95 = function() private$..ci95$value,
        risktable = function() private$..risktable$value,
        censored = function() private$..censored$value,
        medianline = function() private$..medianline$value,
        pplot = function() private$..pplot$value,
        cutp = function() private$..cutp$value,
        calculateRiskScore = function() private$..calculateRiskScore$value,
        numRiskGroups = function() private$..numRiskGroups$value,
        plotRiskGroups = function() private$..plotRiskGroups$value,
        addRiskScore = function() private$..addRiskScore$value,
        addRiskGroup = function() private$..addRiskGroup$value,
        ac = function() private$..ac$value,
        adjexplanatory = function() private$..adjexplanatory$value,
        ac_method = function() private$..ac_method$value,
        showNomogram = function() private$..showNomogram$value,
        use_modelSelection = function() private$..use_modelSelection$value,
        modelSelection = function() private$..modelSelection$value,
        selectionCriteria = function() private$..selectionCriteria$value,
        pEntry = function() private$..pEntry$value,
        pRemoval = function() private$..pRemoval$value,
        use_stratify = function() private$..use_stratify$value,
        stratvar = function() private$..stratvar$value,
        person_time = function() private$..person_time$value,
        time_intervals = function() private$..time_intervals$value,
        rate_multiplier = function() private$..rate_multiplier$value,
        use_tree = function() private$..use_tree$value,
        min_node = function() private$..min_node$value,
        complexity = function() private$..complexity$value,
        max_depth = function() private$..max_depth$value,
        show_terminal_nodes = function() private$..show_terminal_nodes$value),
    private = list(
        ..elapsedtime = NA,
        ..tint = NA,
        ..dxdate = NA,
        ..fudate = NA,
        ..timetypedata = NA,
        ..timetypeoutput = NA,
        ..uselandmark = NA,
        ..landmark = NA,
        ..calculatedtime = NA,
        ..outcome = NA,
        ..outcomeLevel = NA,
        ..dod = NA,
        ..dooc = NA,
        ..awd = NA,
        ..awod = NA,
        ..analysistype = NA,
        ..outcomeredefined = NA,
        ..explanatory = NA,
        ..contexpl = NA,
        ..multievent = NA,
        ..hr = NA,
        ..sty = NA,
        ..ph_cox = NA,
        ..km = NA,
        ..endplot = NA,
        ..byplot = NA,
        ..ci95 = NA,
        ..risktable = NA,
        ..censored = NA,
        ..medianline = NA,
        ..pplot = NA,
        ..cutp = NA,
        ..calculateRiskScore = NA,
        ..numRiskGroups = NA,
        ..plotRiskGroups = NA,
        ..addRiskScore = NA,
        ..addRiskGroup = NA,
        ..ac = NA,
        ..adjexplanatory = NA,
        ..ac_method = NA,
        ..showNomogram = NA,
        ..use_modelSelection = NA,
        ..modelSelection = NA,
        ..selectionCriteria = NA,
        ..pEntry = NA,
        ..pRemoval = NA,
        ..use_stratify = NA,
        ..stratvar = NA,
        ..person_time = NA,
        ..time_intervals = NA,
        ..rate_multiplier = NA,
        ..use_tree = NA,
        ..min_node = NA,
        ..complexity = NA,
        ..max_depth = NA,
        ..show_terminal_nodes = NA)
)

multisurvivalResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "multisurvivalResults",
    inherit = jmvcore::Group,
    active = list(
        todo = function() private$.items[["todo"]],
        text = function() private$.items[["text"]],
        text2 = function() private$.items[["text2"]],
        personTimeTable = function() private$.items[["personTimeTable"]],
        personTimeSummary = function() private$.items[["personTimeSummary"]],
        plot = function() private$.items[["plot"]],
        plot3 = function() private$.items[["plot3"]],
        cox_ph = function() private$.items[["cox_ph"]],
        plot8 = function() private$.items[["plot8"]],
        plotKM = function() private$.items[["plotKM"]],
        risk_score_analysis = function() private$.items[["risk_score_analysis"]],
        risk_score_analysis2 = function() private$.items[["risk_score_analysis2"]],
        riskScoreTable = function() private$.items[["riskScoreTable"]],
        riskScoreMetrics = function() private$.items[["riskScoreMetrics"]],
        riskGroupPlot = function() private$.items[["riskGroupPlot"]],
        stratificationExplanation = function() private$.items[["stratificationExplanation"]],
        calculatedtime = function() private$.items[["calculatedtime"]],
        outcomeredefined = function() private$.items[["outcomeredefined"]],
        addRiskScore = function() private$.items[["addRiskScore"]],
        addRiskGroup = function() private$.items[["addRiskGroup"]],
        plot_adj = function() private$.items[["plot_adj"]],
        plot_nomogram = function() private$.items[["plot_nomogram"]],
        nomogram_display = function() private$.items[["nomogram_display"]],
        tree_summary = function() private$.items[["tree_summary"]],
        tree_plot = function() private$.items[["tree_plot"]],
        node_survival_plots = function() private$.items[["node_survival_plots"]],
        mydataview_modelselection = function() private$.items[["mydataview_modelselection"]],
        text_model_selection = function() private$.items[["text_model_selection"]],
        selection_method = function() private$.items[["selection_method"]],
        text2_model_selection = function() private$.items[["text2_model_selection"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Multivariable Survival Analysis",
                refs=list(
                    "multivariable",
                    "survivaltutorial",
                    "survivalrwnahhas",
                    "ClinicoPathJamoviModule"))
            self$add(jmvcore::Html$new(
                options=options,
                name="todo",
                title="To Do",
                clearWith=list(
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection")))
            self$add(jmvcore::Html$new(
                options=options,
                name="text",
                title="Multivariable Survival",
                refs="finalfit",
                clearWith=list(
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection")))
            self$add(jmvcore::Html$new(
                options=options,
                name="text2",
                title="",
                refs="finalfit",
                clearWith=list(
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection")))
            self$add(jmvcore::Table$new(
                options=options,
                name="personTimeTable",
                title="Person-Time Analysis",
                visible="(person_time)",
                rows=0,
                columns=list(
                    list(
                        `name`="interval", 
                        `title`="Time Interval", 
                        `type`="text"),
                    list(
                        `name`="events", 
                        `title`="Events", 
                        `type`="integer"),
                    list(
                        `name`="person_time", 
                        `title`="Person-Time", 
                        `type`="number", 
                        `format`="zto"),
                    list(
                        `name`="rate", 
                        `title`="Incidence Rate", 
                        `type`="number", 
                        `format`="zto"),
                    list(
                        `name`="rate_ci_lower", 
                        `title`="Lower", 
                        `superTitle`="95% CI", 
                        `type`="number", 
                        `format`="zto"),
                    list(
                        `name`="rate_ci_upper", 
                        `title`="Upper", 
                        `superTitle`="95% CI", 
                        `type`="number", 
                        `format`="zto")),
                clearWith=list(
                    "outcome",
                    "outcomeLevel",
                    "elapsedtime",
                    "rate_multiplier",
                    "time_intervals",
                    "person_time",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection",
                    "person_time")))
            self$add(jmvcore::Html$new(
                options=options,
                name="personTimeSummary",
                title="Person-Time Summary",
                visible="(person_time)",
                clearWith=list(
                    "outcome",
                    "outcomeLevel",
                    "elapsedtime",
                    "rate_multiplier",
                    "time_intervals",
                    "person_time",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection",
                    "person_time")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot",
                title="Hazards Regression Plot",
                width=600,
                height=450,
                renderFun=".plot",
                requiresData=TRUE,
                visible="(hr && sty:t1)",
                refs="finalfit",
                clearWith=list(
                    "hr",
                    "sty",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot3",
                title="Hazards Regression Plot",
                width=800,
                height=600,
                renderFun=".plot3",
                requiresData=TRUE,
                visible="(hr && sty:t3)",
                refs="survminer",
                clearWith=list(
                    "hr",
                    "sty",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection")))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="cox_ph",
                title="Proportional Hazards Assumption",
                visible="(ph_cox)",
                clearWith=list(
                    "explanatory",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "contexpl",
                    "use_modelSelection")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot8",
                title="Proportional Hazards Assumption",
                width=600,
                height=450,
                renderFun=".plot8",
                visible="(ph_cox)",
                requiresData=TRUE,
                clearWith=list(
                    "ph_cox",
                    "endplot",
                    "byplot",
                    "explanatory",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "contexpl",
                    "use_modelSelection")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plotKM",
                title="Kaplan-Meier",
                width=600,
                height=450,
                renderFun=".plotKM",
                requiresData=TRUE,
                visible="(km)",
                refs="finalfit",
                clearWith=list(
                    "km",
                    "endplot",
                    "byplot",
                    "ci95",
                    "risktable",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "adjexplanatory",
                    "pplot",
                    "censored",
                    "medianline",
                    "use_modelSelection")))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="risk_score_analysis",
                title="Risk Score Analysis",
                visible="(calculateRiskScore)",
                clearWith=list(
                    "calculateRiskScore",
                    "outcome",
                    "outcomeLevel",
                    "explanatory",
                    "contexpl",
                    "numRiskGroups",
                    "use_modelSelection")))
            self$add(jmvcore::Html$new(
                options=options,
                name="risk_score_analysis2",
                title="Risk Score Analysis",
                visible="(calculateRiskScore)",
                clearWith=list(
                    "calculateRiskScore",
                    "outcome",
                    "outcomeLevel",
                    "explanatory",
                    "contexpl",
                    "numRiskGroups",
                    "use_modelSelection")))
            self$add(jmvcore::Table$new(
                options=options,
                name="riskScoreTable",
                title="Risk Score Summary",
                visible="(calculateRiskScore)",
                rows=0,
                columns=list(
                    list(
                        `name`="group", 
                        `title`="Risk Group", 
                        `type`="text"),
                    list(
                        `name`="n_patients", 
                        `title`="N", 
                        `type`="integer"),
                    list(
                        `name`="percent", 
                        `title`="Percent", 
                        `type`="number"),
                    list(
                        `name`="median_score", 
                        `title`="Median Score", 
                        `type`="number"),
                    list(
                        `name`="events", 
                        `title`="Events", 
                        `type`="integer")),
                clearWith=list(
                    "calculateRiskScore",
                    "outcome",
                    "outcomeLevel",
                    "explanatory",
                    "contexpl",
                    "numRiskGroups",
                    "use_modelSelection")))
            self$add(jmvcore::Html$new(
                options=options,
                name="riskScoreMetrics",
                title="Risk Score Model Metrics",
                visible="(calculateRiskScore)",
                clearWith=list(
                    "calculateRiskScore",
                    "outcome",
                    "outcomeLevel",
                    "explanatory",
                    "contexpl",
                    "numRiskGroups",
                    "use_modelSelection")))
            self$add(jmvcore::Image$new(
                options=options,
                name="riskGroupPlot",
                title="Risk Group Survival Plot",
                width=600,
                height=450,
                renderFun=".plotRiskGroups",
                requiresData=TRUE,
                visible="(plotRiskGroups)",
                clearWith=list(
                    "calculateRiskScore",
                    "outcome",
                    "outcomeLevel",
                    "explanatory",
                    "contexpl",
                    "numRiskGroups",
                    "use_modelSelection")))
            self$add(jmvcore::Html$new(
                options=options,
                name="stratificationExplanation",
                title="Stratification Notes",
                visible="(use_stratify)",
                clearWith=list(
                    "calculateRiskScore",
                    "outcome",
                    "outcomeLevel",
                    "explanatory",
                    "contexpl",
                    "numRiskGroups",
                    "use_modelSelection")))
            self$add(jmvcore::Output$new(
                options=options,
                name="calculatedtime",
                title="Add Calculated Time to Data",
                varTitle="`Calculated Time in Multivariable Survival Function - from ${ dxdate } to { fudate }`",
                varDescription="Calculated Time from given Dates in Multivariable Survival Analysis",
                clearWith=list(
                    "tint",
                    "dxdate",
                    "fudate")))
            self$add(jmvcore::Output$new(
                options=options,
                name="outcomeredefined",
                title="Add Redefined Outcome to Data",
                varTitle="`Redefined Outcome in Multivariable Survival Function - from ${ outcome } for analysis { analysistype }`",
                varDescription="Redefined Outcome from Outcome based on Analysis Type in Multivariable Survival Analysis",
                clearWith=list(
                    "outcome",
                    "analysistype",
                    "multievent")))
            self$add(jmvcore::Output$new(
                options=options,
                name="addRiskScore",
                title="Add Calculated Risk Score to Data",
                varTitle="`Calculated Risk Score in Multivariable Survival Function`",
                varDescription="Calculated Risk Score Based on Model",
                clearWith=list(
                    "addRiskScore",
                    "calculateRiskScore",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "addRiskGroup")))
            self$add(jmvcore::Output$new(
                options=options,
                name="addRiskGroup",
                title="Add Calculated Risk Group to Data",
                varTitle="`Calculated Risk Group in Multivariable Survival Function`",
                varDescription="Calculated Risk Group Based on Model",
                clearWith=list(
                    "addRiskScore",
                    "calculateRiskScore",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "addRiskGroup")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot_adj",
                title="Adjusted Survival Plot",
                width=600,
                height=450,
                renderFun=".plot_adj",
                visible="(ac)",
                refs="survminer",
                clearWith=list(
                    "ac",
                    "adjexplanatory",
                    "ci95",
                    "risktable",
                    "ac_method",
                    "endplot",
                    "byplot",
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "adjexplanatory",
                    "pplot",
                    "censored",
                    "medianline",
                    "use_modelSelection")))
            self$add(jmvcore::Image$new(
                options=options,
                name="plot_nomogram",
                title="Nomogram",
                width=800,
                height=600,
                requiresData=TRUE,
                renderFun=".plot_nomogram",
                visible="(showNomogram)"))
            self$add(jmvcore::Html$new(
                options=options,
                name="nomogram_display",
                title="Nomogram Scoring Guide",
                visible="(showNomogram)"))
            self$add(jmvcore::Html$new(
                options=options,
                name="tree_summary",
                title="Survival Decision Tree Summary",
                visible="(use_tree)",
                clearWith=list(
                    "use_tree",
                    "min_node",
                    "complexity",
                    "max_depth",
                    "outcome",
                    "outcomeLevel",
                    "elapsedtime",
                    "explanatory",
                    "contexpl")))
            self$add(jmvcore::Image$new(
                options=options,
                name="tree_plot",
                title="Survival Decision Tree",
                width=800,
                height=600,
                renderFun=".plotTree",
                requiresData=TRUE,
                visible="(use_tree)",
                clearWith=list(
                    "use_tree",
                    "min_node",
                    "complexity",
                    "max_depth",
                    "outcome",
                    "outcomeLevel",
                    "elapsedtime",
                    "explanatory",
                    "contexpl")))
            self$add(jmvcore::Image$new(
                options=options,
                name="node_survival_plots",
                title="Survival Curves for Terminal Nodes",
                width=800,
                height=600,
                renderFun=".plotNodeSurvival",
                requiresData=TRUE,
                visible="(use_tree && show_terminal_nodes)",
                clearWith=list(
                    "use_tree",
                    "min_node",
                    "complexity",
                    "max_depth",
                    "show_terminal_nodes",
                    "outcome",
                    "outcomeLevel",
                    "elapsedtime",
                    "explanatory",
                    "contexpl")))
            self$add(jmvcore::Preformatted$new(
                options=options,
                name="mydataview_modelselection",
                title="mydataview_modelselection"))
            self$add(jmvcore::Html$new(
                options=options,
                name="text_model_selection",
                title="Multivariable Survival with Model Selection",
                refs="finalfit",
                visible="(use_modelSelection)",
                clearWith=list(
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection",
                    "modelSelection",
                    "selectionCriteria",
                    "pEntry",
                    "pRemoval")))
            self$add(jmvcore::Html$new(
                options=options,
                name="selection_method",
                title="",
                refs="finalfit",
                visible="(use_modelSelection)",
                clearWith=list(
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection",
                    "modelSelection",
                    "selectionCriteria",
                    "pEntry",
                    "pRemoval")))
            self$add(jmvcore::Html$new(
                options=options,
                name="text2_model_selection",
                title="",
                refs="finalfit",
                visible="(use_modelSelection)",
                clearWith=list(
                    "outcome",
                    "outcomeLevel",
                    "overalltime",
                    "explanatory",
                    "contexpl",
                    "fudate",
                    "dxdate",
                    "tint",
                    "multievent",
                    "use_modelSelection",
                    "modelSelection",
                    "selectionCriteria",
                    "pEntry",
                    "pRemoval")))}))

multisurvivalBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "multisurvivalBase",
    inherit = jmvcore::Analysis,
    public = list(
        initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
            super$initialize(
                package = "jsurvival",
                name = "multisurvival",
                version = c(0,0,3),
                options = options,
                results = multisurvivalResults$new(options=options),
                data = data,
                datasetId = datasetId,
                analysisId = analysisId,
                revision = revision,
                pause = NULL,
                completeWhenFilled = FALSE,
                requiresMissings = FALSE,
                weightsSupport = 'none')
        }))

#' Multivariable Survival Analysis
#'
#' Performs multivariable survival analysis using Cox proportional hazards 
#' regression. In multivariable survival analysis, person-time follow-up is 
#' crucial for properly adjusting for covariates while accounting for varying 
#' observation periods. The Cox proportional hazards model incorporates 
#' person-time by modeling the hazard function, which represents the 
#' instantaneous event rate per unit of person-time. When stratifying analyses 
#' or examining multiple predictors, the model accounts for how these factors 
#' influence event rates relative to the person-time at risk in each subgroup.
#'
#' @examples
#' \donttest{
#' # example will be added
#'}
#' @param data The dataset to be analyzed, provided as a data frame. Must
#'   contain the variables specified in the options below.
#' @param elapsedtime The numeric variable representing follow-up time until
#'   the event or last observation. If \code{tint} = false, this should be a
#'   pre-calculated numeric time variable. If \code{tint} = true, \code{dxdate}
#'   and \code{fudate} will be used to calculate this time.
#' @param tint If true, survival time will be calculated from \code{dxdate}
#'   and \code{fudate}. If false, \code{elapsedtime} should be provided as a
#'   pre-calculated numeric variable.
#' @param dxdate Date of diagnosis. Required if \code{tint} = true. Must match
#'   the format specified in \code{timetypedata}.
#' @param fudate Follow-up date or date of last observation. Required if
#'   \code{tint} = true. Must match the format specified in \code{timetypedata}.
#' @param timetypedata Specifies the format of the date variables in the input
#'   data. This is critical if \code{tint = true}, as \code{dxdate} and
#'   \code{fudate} will be parsed according to this format to calculate survival
#'   time. For example, if your data files record dates as "YYYY-MM-DD", select
#'   \code{ymd}.
#' @param timetypeoutput The units in which survival time is reported in the
#'   output. Choose from days, weeks, months, or years.
#' @param uselandmark If true, applies a landmark analysis starting at a
#'   specified time point.
#' @param landmark The time point (in the units defined by
#'   \code{timetypeoutput}) at which to start landmark analyses. Only used if
#'   \code{uselandmark} = true.
#' @param outcome The outcome variable. Typically indicates event status
#'   (e.g., death, recurrence). For survival analysis, this may be a factor or
#'   numeric event indicator.
#' @param outcomeLevel The level of \code{outcome} considered as the event.
#'   For example, if \code{outcome} is a factor, specify which level indicates
#'   the event occurrence.
#' @param dod The level of \code{outcome} corresponding to death due to
#'   disease, if applicable.
#' @param dooc The level of \code{outcome} corresponding to death due to other
#'   causes, if applicable.
#' @param awd The level of \code{outcome} corresponding to alive with disease,
#'   if applicable.
#' @param awod The level of \code{outcome} corresponding to alive without
#'   disease, if applicable.
#' @param analysistype Type of survival analysis: - overall: All-cause
#'   survival - cause: Cause-specific survival - compete: Competing risks
#'   analysis
#' @param explanatory Categorical explanatory (predictor) variables included
#'   in the Cox model.
#' @param contexpl Continuous explanatory (predictor) variables included in
#'   the Cox model.
#' @param multievent If true, multiple event levels will be considered for
#'   competing risks analysis. Requires specifying \code{dod}, \code{dooc}, etc.
#' @param hr If true, generates a plot of hazard ratios for each explanatory
#'   variable in the Cox model.
#' @param sty The style of the hazard ratio (forest) plot. "finalfit" or
#'   "survminer forestplot".
#' @param ph_cox If true, tests the proportional hazards assumption for the
#'   Cox model. Use if you suspect violations of the PH assumption.
#' @param km If true, produces a Kaplan-Meier survival plot. Useful for
#'   visualization of survival functions without covariate adjustment.
#' @param endplot The maximum follow-up time (in units defined by
#'   \code{timetypeoutput}) to display on survival plots.
#' @param byplot The interval (in units defined by \code{timetypeoutput}) at
#'   which time points or labels are shown on plots.
#' @param ci95 If true, displays 95\% confidence intervals around the survival
#'   estimates on plots.
#' @param risktable If true, displays the number of subjects at risk at each
#'   time point below the survival plot.
#' @param censored If true, marks censored observations (e.g., using tick
#'   marks) on the survival plot.
#' @param medianline If true, displays a line indicating the median survival
#'   time on the survival plot.
#' @param pplot If true, displays the p-value from the survival comparison
#'   test on the survival plot.
#' @param cutp .
#' @param calculateRiskScore If true, calculates a risk score from the Cox
#'   model coefficients for each individual.
#' @param numRiskGroups Select the number of risk groups to create from the
#'   risk scores. The data will be divided into equal quantiles based on this
#'   selection.
#' @param plotRiskGroups If true, stratifies individuals into risk groups
#'   based on their calculated risk scores and plots their survival curves.
#' @param ac .
#' @param adjexplanatory .
#' @param ac_method Method for computing adjusted survival curves
#' @param showNomogram .
#' @param use_modelSelection If true, applies a variable selection procedure
#'   to find the best-fitting model based on criteria like AIC or likelihood
#'   ratio tests.
#' @param modelSelection The method used to select variables: - enter:
#'   Includes all variables (no selection) - forward: Adds variables one at a
#'   time if they improve the model - backward: Removes variables that do not
#'   significantly contribute - both: Combination of forward and backward steps
#' @param selectionCriteria The criterion used for adding or removing
#'   variables in model selection: - aic: Balances model fit and complexity -
#'   lrt: Uses likelihood ratio tests to decide inclusion/removal
#' @param pEntry Significance level at which a variable enters the model
#'   during forward or stepwise selection.
#' @param pRemoval Significance level at which a variable is removed from the
#'   model during backward or stepwise selection.
#' @param use_stratify If true, uses stratification to handle variables that
#'   violate the proportional hazards assumption. Stratification creates
#'   separate baseline hazard functions for different groups.
#' @param stratvar Variables used for stratification. When proportional
#'   hazards are not met, stratification can adjust the model to better fit the
#'   data by allowing different baseline hazards.
#' @param person_time Enable this option to calculate and display person-time
#'   metrics, including total follow-up time and incidence rates. These metrics
#'   help quantify the rate of events per unit of time in your study population.
#' @param time_intervals Specify time intervals for stratified person-time
#'   analysis. Enter a  comma-separated list of time points to create intervals.
#'   For example,  "12, 36, 60" will create intervals 0-12, 12-36, 36-60, and
#'   60+.
#' @param rate_multiplier Specify the multiplier for incidence rates (e.g.,
#'   100 for rates per 100 person-years, 1000 for rates per 1000 person-years).
#' @param use_tree If true, fits a survival decision tree to identify
#'   subgroups with different survival outcomes. Decision trees provide an
#'   intuitive alternative to Cox regression for identifying risk factors.
#' @param min_node The minimum number of observations required in a terminal
#'   node. Larger values create simpler trees that may be more generalizable but
#'   potentially miss important subgroups.
#' @param complexity The complexity parameter for tree pruning. Higher values
#'   result in smaller trees. This parameter controls the trade-off between tree
#'   size and goodness of fit.
#' @param max_depth The maximum depth of the decision tree. Limits the
#'   complexity of the tree to avoid overfitting.
#' @param show_terminal_nodes If true, displays Kaplan-Meier survival curves
#'   for each terminal node of the decision tree.
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$todo} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$text} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$text2} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$personTimeTable} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$personTimeSummary} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot3} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$cox_ph} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$plot8} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plotKM} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$risk_score_analysis} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$risk_score_analysis2} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$riskScoreTable} \tab \tab \tab \tab \tab a table \cr
#'   \code{results$riskScoreMetrics} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$riskGroupPlot} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$stratificationExplanation} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$calculatedtime} \tab \tab \tab \tab \tab an output \cr
#'   \code{results$outcomeredefined} \tab \tab \tab \tab \tab an output \cr
#'   \code{results$addRiskScore} \tab \tab \tab \tab \tab an output \cr
#'   \code{results$addRiskGroup} \tab \tab \tab \tab \tab an output \cr
#'   \code{results$plot_adj} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$plot_nomogram} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$nomogram_display} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$tree_summary} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$tree_plot} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$node_survival_plots} \tab \tab \tab \tab \tab an image \cr
#'   \code{results$mydataview_modelselection} \tab \tab \tab \tab \tab a preformatted \cr
#'   \code{results$text_model_selection} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$selection_method} \tab \tab \tab \tab \tab a html \cr
#'   \code{results$text2_model_selection} \tab \tab \tab \tab \tab a html \cr
#' }
#'
#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example:
#'
#' \code{results$personTimeTable$asDF}
#'
#' \code{as.data.frame(results$personTimeTable)}
#'
#' @export
multisurvival <- function(
    data,
    elapsedtime,
    tint = FALSE,
    dxdate,
    fudate,
    timetypedata = "ymd",
    timetypeoutput = "months",
    uselandmark = FALSE,
    landmark = 3,
    outcome,
    outcomeLevel,
    dod,
    dooc,
    awd,
    awod,
    analysistype = "overall",
    explanatory,
    contexpl,
    multievent = FALSE,
    hr = FALSE,
    sty = "t1",
    ph_cox = FALSE,
    km = FALSE,
    endplot = 60,
    byplot = 12,
    ci95 = FALSE,
    risktable = FALSE,
    censored = FALSE,
    medianline = "none",
    pplot = TRUE,
    cutp = "12, 36, 60",
    calculateRiskScore = FALSE,
    numRiskGroups = "four",
    plotRiskGroups = FALSE,
    ac = FALSE,
    adjexplanatory,
    ac_method = "average",
    showNomogram = FALSE,
    use_modelSelection = FALSE,
    modelSelection = "enter",
    selectionCriteria = "aic",
    pEntry = 0.05,
    pRemoval = 0.1,
    use_stratify = FALSE,
    stratvar,
    person_time = FALSE,
    time_intervals = "12, 36, 60",
    rate_multiplier = 100,
    use_tree = FALSE,
    min_node = 20,
    complexity = 0.01,
    max_depth = 5,
    show_terminal_nodes = TRUE) {

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

    if ( ! missing(elapsedtime)) elapsedtime <- jmvcore::resolveQuo(jmvcore::enquo(elapsedtime))
    if ( ! missing(dxdate)) dxdate <- jmvcore::resolveQuo(jmvcore::enquo(dxdate))
    if ( ! missing(fudate)) fudate <- jmvcore::resolveQuo(jmvcore::enquo(fudate))
    if ( ! missing(outcome)) outcome <- jmvcore::resolveQuo(jmvcore::enquo(outcome))
    if ( ! missing(explanatory)) explanatory <- jmvcore::resolveQuo(jmvcore::enquo(explanatory))
    if ( ! missing(contexpl)) contexpl <- jmvcore::resolveQuo(jmvcore::enquo(contexpl))
    if ( ! missing(adjexplanatory)) adjexplanatory <- jmvcore::resolveQuo(jmvcore::enquo(adjexplanatory))
    if ( ! missing(stratvar)) stratvar <- jmvcore::resolveQuo(jmvcore::enquo(stratvar))
    if (missing(data))
        data <- jmvcore::marshalData(
            parent.frame(),
            `if`( ! missing(elapsedtime), elapsedtime, NULL),
            `if`( ! missing(dxdate), dxdate, NULL),
            `if`( ! missing(fudate), fudate, NULL),
            `if`( ! missing(outcome), outcome, NULL),
            `if`( ! missing(explanatory), explanatory, NULL),
            `if`( ! missing(contexpl), contexpl, NULL),
            `if`( ! missing(adjexplanatory), adjexplanatory, NULL),
            `if`( ! missing(stratvar), stratvar, NULL))

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

    options <- multisurvivalOptions$new(
        elapsedtime = elapsedtime,
        tint = tint,
        dxdate = dxdate,
        fudate = fudate,
        timetypedata = timetypedata,
        timetypeoutput = timetypeoutput,
        uselandmark = uselandmark,
        landmark = landmark,
        outcome = outcome,
        outcomeLevel = outcomeLevel,
        dod = dod,
        dooc = dooc,
        awd = awd,
        awod = awod,
        analysistype = analysistype,
        explanatory = explanatory,
        contexpl = contexpl,
        multievent = multievent,
        hr = hr,
        sty = sty,
        ph_cox = ph_cox,
        km = km,
        endplot = endplot,
        byplot = byplot,
        ci95 = ci95,
        risktable = risktable,
        censored = censored,
        medianline = medianline,
        pplot = pplot,
        cutp = cutp,
        calculateRiskScore = calculateRiskScore,
        numRiskGroups = numRiskGroups,
        plotRiskGroups = plotRiskGroups,
        ac = ac,
        adjexplanatory = adjexplanatory,
        ac_method = ac_method,
        showNomogram = showNomogram,
        use_modelSelection = use_modelSelection,
        modelSelection = modelSelection,
        selectionCriteria = selectionCriteria,
        pEntry = pEntry,
        pRemoval = pRemoval,
        use_stratify = use_stratify,
        stratvar = stratvar,
        person_time = person_time,
        time_intervals = time_intervals,
        rate_multiplier = rate_multiplier,
        use_tree = use_tree,
        min_node = min_node,
        complexity = complexity,
        max_depth = max_depth,
        show_terminal_nodes = show_terminal_nodes)

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

    analysis$run()

    analysis$results
}
sbalci/jsurvival documentation built on July 4, 2025, 5:26 p.m.