Skip to contents

Performs comprehensive univariate and stratified 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.

Key Features:

  • Kaplan-Meier survival curves with multiple plot types

  • Cox proportional hazards regression (univariate and stratified)

  • Median survival time with confidence intervals

  • Restricted Mean Survival Time (RMST) analysis

  • Person-time analysis with incidence rates

  • Competing risks and cause-specific survival

  • Landmark analysis for conditional survival

  • Proportional hazards assumption testing

  • Model residual diagnostics

  • Pairwise group comparisons with multiple testing correction

Statistical Methods:

  • Kaplan-Meier estimator for survival probabilities

  • Log-rank test for group comparisons

  • Cox proportional hazards model for risk assessment

  • Competing risks analysis using cumulative incidence functions

  • RMST for robust survival comparisons

Visualization Options:

  • Standard survival curves

  • Cumulative events and hazard plots

  • KMunicate-style plots for publication

  • Log-log plots for proportional hazards assessment

  • Residual diagnostic plots

Usage

.escapeVariableNames(var_names)

Arguments

data

The data as a data frame

elapsedtime

Numeric variable containing survival time (time to event or censoring)

tint

Logical. Use dates to calculate survival time from diagnosis and follow-up dates

dxdate

Date variable for diagnosis date (when tint = TRUE)

fudate

Date variable for follow-up/event date (when tint = TRUE)

explanatory

Factor variable for group comparisons (e.g., treatment groups, risk categories)

outcome

Event indicator variable (binary: 0=censored, 1=event) or factor for multi-state outcomes

outcomeLevel

Event level when using factor outcome variable

dod

Dead of disease level (for competing risks analysis)

dooc

Dead of other causes level (for competing risks analysis)

awd

Alive with disease level (for competing risks analysis)

awod

Alive without disease level (for competing risks analysis)

analysistype

Type of survival analysis: "overall", "cause", or "compete"

cutp

Time points for survival probability estimation (comma-separated)

timetypedata

Date format in data: "ymd", "dmy", "mdy", etc.

timetypeoutput

Time unit for output: "days", "weeks", "months", "years"

uselandmark

Logical. Perform landmark analysis

landmark

Landmark time point for conditional survival analysis

pw

Logical. Perform pairwise group comparisons

padjustmethod

Multiple testing correction method for pairwise comparisons

ph_cox

Logical. Test proportional hazards assumption

stratified_cox

Logical. Use stratified Cox regression

strata_variable

Variable for Cox model stratification

rmst_analysis

Logical. Calculate Restricted Mean Survival Time

rmst_tau

Time horizon for RMST calculation (uses 75th percentile if NULL)

residual_diagnostics

Logical. Calculate and display model residuals

export_survival_data

Logical. Export survival estimates for external analysis

person_time

Logical. Calculate person-time metrics and incidence rates

time_intervals

Time intervals for stratified person-time analysis

rate_multiplier

Multiplier for incidence rates (e.g., 100 for per 100 person-years)

sc

Logical. Display survival curve plot

ce

Logical. Display cumulative events plot

ch

Logical. Display cumulative hazard plot

kmunicate

Logical. Display KMunicate-style plot

loglog

Logical. Display log-log plot for proportional hazards assessment

endplot

Maximum time for plot x-axis

ybegin_plot

Minimum value for plot y-axis

yend_plot

Maximum value for plot y-axis

byplot

Time interval for plot axis breaks

multievent

Logical. Use multiple event levels for competing risks

ci95

Logical. Display 95% confidence intervals on plots

risktable

Logical. Display risk table below survival curves

censored

Logical. Display censoring marks on survival curves

pplot

Logical. Display p-value on plots

medianline

Type of median survival line: "none", "h", "v", "hv"

Value

A comprehensive results object containing survival analysis outputs

Details

Analysis Types:

  • Overall Survival: Time from study entry to death from any cause

  • Cause-Specific Survival: Time to death from specific cause (censoring other deaths)

  • Competing Risks: Accounts for multiple types of events that prevent observation of the primary outcome

Person-Time Analysis: Calculates incidence rates accounting for varying follow-up times. Particularly useful for:

  • Studies with differential loss to follow-up

  • Comparison of event rates across populations

  • Assessment of time-varying risk

Restricted Mean Survival Time (RMST): Alternative to median survival when survival curves don't reach 50% or for comparing survival over a specific time horizon. Represents the area under the survival curve up to a specified time point.

Model Diagnostics:

  • Proportional hazards assumption testing using Schoenfeld residuals

  • Martingale and deviance residuals for outlier detection

  • Log-log plots for visual assessment of proportional hazards

References

Klein JP, Moeschberger ML (2003). Survival Analysis: Techniques for Censored and Truncated Data. Springer.

Therneau TM, Grambsch PM (2000). Modeling Survival Data: Extending the Cox Model. Springer.

Royston P, Parmar MK (2013). Restricted mean survival time: an alternative to the hazard ratio for the design and analysis of randomized trials with a time-to-event outcome. BMC Medical Research Methodology 13:152.

Examples

# \donttest{
# Basic survival analysis
data("histopathologySurvival", package = "ClinicoPathJamoviModule")
#> Error in find.package(package, lib.loc, verbose = verbose): there is no package called ‘ClinicoPathJamoviModule’

# Standard survival analysis with median and survival probabilities
survival_result <- survival(
  data = histopathologySurvival,
  elapsedtime = "OverallSurvival_indays",
  outcome = "Outcome",
  outcomeLevel = "Dead",
  explanatory = "Grade",
  timetypeoutput = "months",
  cutp = "12, 36, 60",
  sc = TRUE,
  pw = TRUE
)
#> Error: object 'histopathologySurvival' not found

# Survival analysis with person-time metrics
survival_with_pt <- survival(
  data = histopathologySurvival,
  elapsedtime = "OverallSurvival_indays", 
  outcome = "Outcome",
  outcomeLevel = "Dead",
  explanatory = "Stage",
  person_time = TRUE,
  time_intervals = "365, 1095, 1825",
  rate_multiplier = 1000
)
#> Error: object 'histopathologySurvival' not found

# RMST analysis for non-proportional hazards
rmst_analysis <- survival(
  data = histopathologySurvival,
  elapsedtime = "OverallSurvival_indays",
  outcome = "Outcome", 
  outcomeLevel = "Dead",
  explanatory = "Treatment",
  rmst_analysis = TRUE,
  rmst_tau = 1095  # 3 years
)
#> Error: object 'histopathologySurvival' not found

# Competing risks analysis
competing_risks <- survival(
  data = cancer_data,
  elapsedtime = "survival_days",
  outcome = "death_cause",
  multievent = TRUE,
  dod = "Cancer",
  dooc = "Other",
  awd = "Alive_Disease",
  awod = "Alive_Free",
  analysistype = "compete",
  explanatory = "risk_group"
)
#> Error: object 'cancer_data' not found

# Landmark analysis for conditional survival
landmark_survival <- survival(
  data = histopathologySurvival,
  elapsedtime = "OverallSurvival_indays",
  outcome = "Outcome",
  outcomeLevel = "Dead", 
  explanatory = "Grade",
  uselandmark = TRUE,
  landmark = 365  # 1-year conditional survival
)
#> Error: object 'histopathologySurvival' not found

# Date-based survival calculation
date_survival <- survival(
  data = clinical_data,
  tint = TRUE,
  dxdate = "diagnosis_date",
  fudate = "last_contact_date",
  timetypedata = "ymd",
  timetypeoutput = "months",
  outcome = "vital_status",
  outcomeLevel = "Dead",
  explanatory = "treatment_arm"
)
#> Error: object 'clinical_data' not found
# }