# This file is automatically generated, you probably don't want to edit this
singlearmOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"singlearmOptions",
inherit = jmvcore::Options,
public = list(
initialize = function(
elapsedtime = NULL,
tint = FALSE,
dxdate = NULL,
fudate = NULL,
outcome = NULL,
outcomeLevel = NULL,
dod = NULL,
dooc = NULL,
awd = NULL,
awod = NULL,
analysistype = "overall",
cutp = "12, 36, 60",
timetypedata = "ymd",
timetypeoutput = "months",
uselandmark = FALSE,
landmark = 3,
sc = FALSE,
kmunicate = FALSE,
ce = FALSE,
ch = FALSE,
endplot = 60,
ybegin_plot = 0,
yend_plot = 1,
byplot = 12,
multievent = FALSE,
ci95 = FALSE,
risktable = FALSE,
censored = FALSE,
medianline = "none", ...) {
super$initialize(
package="jsurvival",
name="singlearm",
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$..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$..cutp <- jmvcore::OptionString$new(
"cutp",
cutp,
default="12, 36, 60")
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$..sc <- jmvcore::OptionBool$new(
"sc",
sc,
default=FALSE)
private$..kmunicate <- jmvcore::OptionBool$new(
"kmunicate",
kmunicate,
default=FALSE)
private$..ce <- jmvcore::OptionBool$new(
"ce",
ce,
default=FALSE)
private$..ch <- jmvcore::OptionBool$new(
"ch",
ch,
default=FALSE)
private$..endplot <- jmvcore::OptionInteger$new(
"endplot",
endplot,
default=60)
private$..ybegin_plot <- jmvcore::OptionNumber$new(
"ybegin_plot",
ybegin_plot,
default=0)
private$..yend_plot <- jmvcore::OptionNumber$new(
"yend_plot",
yend_plot,
default=1)
private$..byplot <- jmvcore::OptionInteger$new(
"byplot",
byplot,
default=12)
private$..multievent <- jmvcore::OptionBool$new(
"multievent",
multievent,
default=FALSE)
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")
self$.addOption(private$..elapsedtime)
self$.addOption(private$..tint)
self$.addOption(private$..dxdate)
self$.addOption(private$..fudate)
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$..cutp)
self$.addOption(private$..timetypedata)
self$.addOption(private$..timetypeoutput)
self$.addOption(private$..uselandmark)
self$.addOption(private$..landmark)
self$.addOption(private$..sc)
self$.addOption(private$..kmunicate)
self$.addOption(private$..ce)
self$.addOption(private$..ch)
self$.addOption(private$..endplot)
self$.addOption(private$..ybegin_plot)
self$.addOption(private$..yend_plot)
self$.addOption(private$..byplot)
self$.addOption(private$..multievent)
self$.addOption(private$..ci95)
self$.addOption(private$..risktable)
self$.addOption(private$..censored)
self$.addOption(private$..medianline)
}),
active = list(
elapsedtime = function() private$..elapsedtime$value,
tint = function() private$..tint$value,
dxdate = function() private$..dxdate$value,
fudate = function() private$..fudate$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,
cutp = function() private$..cutp$value,
timetypedata = function() private$..timetypedata$value,
timetypeoutput = function() private$..timetypeoutput$value,
uselandmark = function() private$..uselandmark$value,
landmark = function() private$..landmark$value,
sc = function() private$..sc$value,
kmunicate = function() private$..kmunicate$value,
ce = function() private$..ce$value,
ch = function() private$..ch$value,
endplot = function() private$..endplot$value,
ybegin_plot = function() private$..ybegin_plot$value,
yend_plot = function() private$..yend_plot$value,
byplot = function() private$..byplot$value,
multievent = function() private$..multievent$value,
ci95 = function() private$..ci95$value,
risktable = function() private$..risktable$value,
censored = function() private$..censored$value,
medianline = function() private$..medianline$value),
private = list(
..elapsedtime = NA,
..tint = NA,
..dxdate = NA,
..fudate = NA,
..calculatedtime = NA,
..outcome = NA,
..outcomeLevel = NA,
..dod = NA,
..dooc = NA,
..awd = NA,
..awod = NA,
..analysistype = NA,
..outcomeredefined = NA,
..cutp = NA,
..timetypedata = NA,
..timetypeoutput = NA,
..uselandmark = NA,
..landmark = NA,
..sc = NA,
..kmunicate = NA,
..ce = NA,
..ch = NA,
..endplot = NA,
..ybegin_plot = NA,
..yend_plot = NA,
..byplot = NA,
..multievent = NA,
..ci95 = NA,
..risktable = NA,
..censored = NA,
..medianline = NA)
)
singlearmResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"singlearmResults",
inherit = jmvcore::Group,
active = list(
todo = function() private$.items[["todo"]],
medianSummary = function() private$.items[["medianSummary"]],
medianTable = function() private$.items[["medianTable"]],
survTableSummary = function() private$.items[["survTableSummary"]],
survTable = function() private$.items[["survTable"]],
plot = function() private$.items[["plot"]],
plot2 = function() private$.items[["plot2"]],
plot3 = function() private$.items[["plot3"]],
plot6 = function() private$.items[["plot6"]],
calculatedtime = function() private$.items[["calculatedtime"]],
outcomeredefined = function() private$.items[["outcomeredefined"]]),
private = list(),
public=list(
initialize=function(options) {
super$initialize(
options=options,
name="",
title="Single Arm Survival",
refs=list(
"finalfit",
"survival",
"survminer",
"ClinicoPathJamoviModule",
"survivaltutorial",
"survivalrwnahhas"))
self$add(jmvcore::Html$new(
options=options,
name="todo",
title="To Do",
clearWith=list(
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent")))
self$add(jmvcore::Preformatted$new(
options=options,
name="medianSummary",
title="Median Survival Summary and Table",
clearWith=list(
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent")))
self$add(jmvcore::Table$new(
options=options,
name="medianTable",
title="Median Survival Table",
rows=0,
columns=list(
list(
`name`="records",
`title`="Records",
`type`="integer"),
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")),
clearWith=list(
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent")))
self$add(jmvcore::Preformatted$new(
options=options,
name="survTableSummary",
title="1, 3, 5-yr Survival Summary and Table",
clearWith=list(
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent")))
self$add(jmvcore::Table$new(
options=options,
name="survTable",
title="1, 3, 5 year Survival",
rows=0,
columns=list(
list(
`name`="time",
`title`="time",
`type`="integer"),
list(
`name`="n.risk",
`title`="Number at Risk",
`type`="integer"),
list(
`name`="n.event",
`title`="Number of Events",
`type`="integer"),
list(
`name`="surv",
`title`="Survival",
`type`="number",
`format`="pc"),
list(
`name`="lower",
`title`="Lower",
`superTitle`="95% Confidence Interval",
`type`="number",
`format`="pc"),
list(
`name`="upper",
`title`="Upper",
`superTitle`="95% Confidence Interval",
`type`="number",
`format`="pc")),
clearWith=list(
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent")))
self$add(jmvcore::Image$new(
options=options,
name="plot",
title="Survival Plot",
width=600,
height=450,
renderFun=".plot",
visible="(sc)",
requiresData=TRUE,
clearWith=list(
"sc",
"endplot",
"byplot",
"sas",
"ci95",
"risktable",
"censored",
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent")))
self$add(jmvcore::Image$new(
options=options,
name="plot2",
title="Cumulative Events",
width=600,
height=450,
renderFun=".plot2",
visible="(ce)",
requiresData=TRUE,
clearWith=list(
"ce",
"endplot",
"byplot",
"sas",
"ci95",
"risktable",
"censored",
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent")))
self$add(jmvcore::Image$new(
options=options,
name="plot3",
title="Cumulative Hazard",
width=600,
height=450,
renderFun=".plot3",
visible="(ch)",
requiresData=TRUE,
clearWith=list(
"ch",
"endplot",
"byplot",
"sas",
"ci95",
"risktable",
"censored",
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent")))
self$add(jmvcore::Image$new(
options=options,
name="plot6",
title="KMunicate-Style Plot",
width=600,
height=450,
renderFun=".plot6",
visible="(kmunicate)",
requiresData=TRUE,
clearWith=list(
"kmunicate",
"endplot",
"byplot",
"sas",
"outcome",
"outcomeLevel",
"overalltime",
"fudate",
"dxdate",
"tint",
"multievent"),
refs=list(
"KMunicate",
"KMunicate2")))
self$add(jmvcore::Output$new(
options=options,
name="calculatedtime",
title="Add Calculated Time to Data",
varTitle="Calculated Time Single Arm",
varDescription="`Calculated Time from given Dates in Single Arm Analysis - from ${ dxdate } to { fudate }`",
clearWith=list(
"tint",
"dxdate",
"fudate")))
self$add(jmvcore::Output$new(
options=options,
name="outcomeredefined",
title="Add Redefined Outcome to Data",
varTitle="Redefined Outcome Single Arm",
varDescription="`Redefined Outcome - from ${ outcome } for analysis { analysistype } in Single Arm Analysis`",
clearWith=list(
"outcome",
"analysistype",
"multievent",
"outcomeLevel")))}))
singlearmBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"singlearmBase",
inherit = jmvcore::Analysis,
public = list(
initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
super$initialize(
package = "jsurvival",
name = "singlearm",
version = c(1,0,0),
options = options,
results = singlearmResults$new(options=options),
data = data,
datasetId = datasetId,
analysisId = analysisId,
revision = revision,
pause = NULL,
completeWhenFilled = FALSE,
requiresMissings = FALSE,
weightsSupport = 'none')
}))
#' Single Arm Survival
#'
#' Performs survival analysis for a single cohort of patients without group
#' comparisons. Use this when you want to analyze overall survival
#' characteristics of your entire study population - for example, to determine
#' median survival time or 1/3/5-year survival rates for all patients
#' collectively. This differs from regular survival analysis which compares
#' survival between groups.
#'
#' @examples
#' \donttest{
#' # Example analyzing overall survival for a patient cohort:
#' # singlearm(
#' # data = patient_data,
#' # time = "months_survival",
#' # outcome = "death_status",
#' # outcome_level = "Dead"
#' # )
#'}
#' @param data The data as a data frame.
#' @param elapsedtime The time-to-event or follow-up duration for each
#' patient. Should be numeric and continuous, measured in consistent units
#' (e.g., months or years). Can be calculated automatically from dates if
#' using the date options below.
#' @param tint Enable this option if you want to calculate survival time from
#' dates in your data. This is useful when you have separate columns for
#' diagnosis date and follow-up date and want to calculate the time elapsed
#' between them.
#' @param dxdate The date of diagnosis or study entry for each patient. Should
#' be in a consistent date format (e.g., YYYY-MM-DD).
#' @param fudate The date of last follow-up or event for each patient. Should
#' be in a consistent date format (e.g., YYYY-MM-DD).
#' @param outcome The outcome or event of interest for each patient. Should be
#' a factor or numeric variable indicating whether the patient experienced the
#' event (e.g., death) or censoring (e.g., end of follow-up).
#' @param outcomeLevel Select the level of the outcome variable that
#' represents the event of interest. For example, if the outcome variable is
#' "death_status" with levels "Alive" and "Dead", select "Dead" as the event
#' level.
#' @param dod Select the level of the outcome variable that represents death
#' due to disease. This is useful for competing risk analysis when there are
#' multiple event types.
#' @param dooc Select the level of the outcome variable that represents death
#' due to other causes. This is useful for competing risk analysis when there
#' are multiple event types.
#' @param awd Select the level of the outcome variable that represents being
#' alive with disease. This is useful for competing risk analysis when there
#' are multiple event types.
#' @param awod Select the level of the outcome variable that represents being
#' alive without disease. This is useful for competing risk analysis when
#' there are multiple event types.
#' @param analysistype Select the type of survival analysis to perform.
#' "Overall" analyzes the survival of all patients regardless of event type.
#' "Cause Specific" analyzes the survival for a specific event type (e.g.,
#' death due to disease). "Competing Risk" analyzes the survival for multiple
#' event types simultaneously.
#' @param cutp Specify the time points at which to calculate survival
#' probabilities. Enter a comma-separated list of time points in consistent
#' units (e.g., months or years). For example, "12, 36, 60" calculates
#' survival probabilities at 1, 3, and 5 years.
#' @param timetypedata select the time type in data (e.g., YYYY-MM-DD)
#' @param timetypeoutput select the time type in output (default is months)
#' @param uselandmark Enables landmark analysis, which addresses immortal time
#' bias by analyzing survival only for patients who survive to a specified
#' timepoint (the landmark). Use this when you want to eliminate the effect of
#' early deaths or when comparing treatments that can only be given to
#' patients who survive long enough to receive them.
#' @param landmark Enables landmark analysis, which addresses immortal time
#' bias by analyzing survival only for patients who survive to a specified
#' timepoint (the landmark). Use this when you want to eliminate the effect of
#' early deaths or when comparing treatments that can only be given to
#' patients who survive long enough to receive them.
#' @param sc Enable this option to generate a Kaplan-Meier survival plot with
#' confidence intervals. This plot shows the estimated survival probability
#' over time and is useful for visualizing survival trends in your data.
#' @param kmunicate Enable this option to generate a publication-ready
#' survival plot in the style of KMunicate. This plot shows the estimated
#' survival probability over time with confidence intervals and is suitable
#' for publication or presentation.
#' @param ce Enable this option to calculate and plot the cumulative number of
#' events over time. This plot shows the total number of events (e.g., deaths)
#' that have occurred at each time point and is useful for visualizing event
#' rates in your data.
#' @param ch Enable this option to calculate and plot the cumulative hazard
#' function over time. This plot shows the cumulative risk of experiencing the
#' event (e.g., death) at each time point and is useful for visualizing the
#' risk of the event over time.
#' @param endplot The maximum time point to include in the survival plots.
#' This is the end time for the survival curves and cumulative event/hazard
#' plots. Enter a positive integer representing the time in consistent units
#' (e.g., months or years).
#' @param ybegin_plot The minimum value for the y-axis in the survival plots.
#' Enter a number between 0 and 1 to set the lower limit of the y-axis.
#' @param yend_plot The maximum value for the y-axis in the survival plots.
#' Enter a number between 0 and 1 to set the upper limit of the y-axis.
#' @param byplot The interval for plotting survival probabilities. Enter a
#' positive integer representing the time interval in consistent units (e.g.,
#' months or years).
#' @param multievent Enable this option to perform survival analysis for
#' datasets with multiple event levels. This is useful for competing risk
#' analysis when there are multiple event types (e.g., death due to disease,
#' death due to other causes).
#' @param ci95 Enable this option to display 95\% confidence intervals on the
#' survival plots. These intervals show the range of uncertainty around the
#' estimated survival probabilities and are useful for assessing the precision
#' of the estimates.
#' @param risktable Enable this option to display a table of risk estimates at
#' each time point. This table shows the estimated survival probability,
#' cumulative event rate, and cumulative hazard at each time point and is
#' useful for summarizing the survival characteristics of your data.
#' @param censored Enable this option to display censored observations on the
#' survival plots. Censored observations are patients who have not experienced
#' the event of interest by the end of follow-up and are indicated by vertical
#' ticks on the survival curves.
#' @param medianline If true, displays a line indicating the median survival
#' time on the survival plot.
#' @return A results object containing:
#' \tabular{llllll}{
#' \code{results$todo} \tab \tab \tab \tab \tab a html \cr
#' \code{results$medianSummary} \tab \tab \tab \tab \tab a preformatted \cr
#' \code{results$medianTable} \tab \tab \tab \tab \tab a table \cr
#' \code{results$survTableSummary} \tab \tab \tab \tab \tab a preformatted \cr
#' \code{results$survTable} \tab \tab \tab \tab \tab a table \cr
#' \code{results$plot} \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
#' \code{results$plot6} \tab \tab \tab \tab \tab an image \cr
#' \code{results$calculatedtime} \tab \tab \tab \tab \tab an output \cr
#' \code{results$outcomeredefined} \tab \tab \tab \tab \tab an output \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
singlearm <- function(
data,
elapsedtime,
tint = FALSE,
dxdate,
fudate,
outcome,
outcomeLevel,
dod,
dooc,
awd,
awod,
analysistype = "overall",
cutp = "12, 36, 60",
timetypedata = "ymd",
timetypeoutput = "months",
uselandmark = FALSE,
landmark = 3,
sc = FALSE,
kmunicate = FALSE,
ce = FALSE,
ch = FALSE,
endplot = 60,
ybegin_plot = 0,
yend_plot = 1,
byplot = 12,
multievent = FALSE,
ci95 = FALSE,
risktable = FALSE,
censored = FALSE,
medianline = "none") {
if ( ! requireNamespace("jmvcore", quietly=TRUE))
stop("singlearm 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(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))
options <- singlearmOptions$new(
elapsedtime = elapsedtime,
tint = tint,
dxdate = dxdate,
fudate = fudate,
outcome = outcome,
outcomeLevel = outcomeLevel,
dod = dod,
dooc = dooc,
awd = awd,
awod = awod,
analysistype = analysistype,
cutp = cutp,
timetypedata = timetypedata,
timetypeoutput = timetypeoutput,
uselandmark = uselandmark,
landmark = landmark,
sc = sc,
kmunicate = kmunicate,
ce = ce,
ch = ch,
endplot = endplot,
ybegin_plot = ybegin_plot,
yend_plot = yend_plot,
byplot = byplot,
multievent = multievent,
ci95 = ci95,
risktable = risktable,
censored = censored,
medianline = medianline)
analysis <- singlearmClass$new(
options = options,
data = data)
analysis$run()
analysis$results
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.