Skip to contents

Performs univariate survival analysis comparing survival between groups. This analysis calculates person-time follow-up for each group and uses this to derive accurate survival estimates and incidence rates that account for varying follow-up durations across groups. The Cox proportional hazards model incorporates person-time by modeling the hazard function, which represents the instantaneous event rate per unit of person-time.

Usage

survival(
  data,
  elapsedtime,
  tint = FALSE,
  dxdate,
  fudate,
  explanatory,
  outcome,
  outcomeLevel,
  dod,
  dooc,
  awd,
  awod,
  analysistype = "overall",
  cutp = "12, 36, 60",
  timetypedata = "ymd",
  timetypeoutput = "months",
  uselandmark = FALSE,
  landmark = 3,
  pw = FALSE,
  padjustmethod = "holm",
  ph_cox = FALSE,
  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,
  pplot = TRUE,
  medianline = "none",
  person_time = FALSE,
  time_intervals = "12, 36, 60",
  rate_multiplier = 100,
  rmst_analysis = FALSE,
  rmst_tau = 0,
  stratified_cox = FALSE,
  strata_variable,
  residual_diagnostics = FALSE,
  export_survival_data = FALSE,
  loglog = FALSE
)

Arguments

data

The data as a data frame.

elapsedtime

The time elapsed from the start of the study to the event or censoring.

tint

If the time is in date format, select this option to calculate the survival time. The time will be calculated as the difference between the event date and the diagnosis date. If the follow-up date is available, the time will be calculated as the difference between the event date and the follow-up date.

dxdate

The date of diagnosis. If the time is in date format, the time will be calculated as the difference between the event date and the diagnosis date.

fudate

The date of follow-up. If the time is in date format, the time will be calculated as the difference between the event date and the follow-up date.

explanatory

The explanatory variable that will be used to compare the survival times of different groups.

outcome

The outcome variable that will be used to compare the survival times of different groups.

outcomeLevel

The level of the outcome variable that will be used as the event level.

dod

.

dooc

.

awd

.

awod

.

analysistype

.

cutp

.

timetypedata

select the time type in data

timetypeoutput

select the time type in output

uselandmark

.

landmark

.

pw

.

padjustmethod

.

ph_cox

.

sc

.

kmunicate

.

ce

.

ch

.

endplot

.

ybegin_plot

.

yend_plot

.

byplot

.

multievent

.

ci95

.

risktable

.

censored

.

pplot

.

medianline

If true, displays a line indicating the median survival time on the survival plot.

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.

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+.

rate_multiplier

Specify the multiplier for incidence rates (e.g., 100 for rates per 100 person-years, 1000 for rates per 1000 person-years).

rmst_analysis

Calculate Restricted Mean Survival Time, which represents the average survival time up to a specified time horizon. Useful when median survival cannot be estimated or for comparing survival over a specific time period.

rmst_tau

Time horizon for RMST calculation. If 0 or not specified, uses the 75th percentile of follow-up time. Should be specified in the same units as the survival time.

stratified_cox

Perform stratified Cox regression to account for non-proportional hazards or unmeasured confounders that affect baseline hazard.

strata_variable

Variable to use for stratification in Cox regression. This variable should represent groups with different baseline hazards.

residual_diagnostics

Calculate and display Cox model residuals for diagnostic purposes, including Martingale, deviance, score, and Schoenfeld residuals.

export_survival_data

Export detailed survival estimates for external analysis, including survival probabilities, confidence intervals, and risk tables at multiple time points.

loglog

Display log-log survival plot for visual assessment of proportional hazards assumption. Parallel lines suggest proportional hazards.

Value

A results object containing:

results$subtitlea preformatted
results$todoa html
results$medianSummarya preformatted
results$medianTablea table
results$coxSummarya preformatted
results$coxTablea table
results$tCoxtext2a html
results$cox_pha preformatted
results$plot8an image
results$survTableSummarya preformatted
results$survTablea table
results$personTimeTablea table
results$personTimeSummarya html
results$rmstTablea table
results$rmstSummarya preformatted
results$residualsTablea table
results$survivalExportan output
results$survivalExportSummarya html
results$pairwiseSummarya preformatted
results$pairwiseTablea table
results$plotan image
results$plot2an image
results$plot3an image
results$plot6an image
results$plot7an image
results$residualsPlotan image
results$calculatedtimean output
results$outcomeredefinedan output

Tables can be converted to data frames with asDF or as.data.frame. For example:

results$medianTable$asDF

as.data.frame(results$medianTable)

Examples

# example will be added