jSurvival: Survival Analysis with Oncology Data
ClinicoPath Team
2025-10-09
Source:vignettes/jsurvival-01-oncodatasets-examples.Rmd
jsurvival-01-oncodatasets-examples.Rmd
Introduction
This vignette demonstrates survival analysis capabilities of the
jSurvival module using real oncology datasets from the
OncoDataSets
package. We’ll cover Kaplan-Meier analysis,
Cox regression, competing risks, and advanced survival modeling.
Example 1: Melanoma Survival Analysis
The Melanoma dataset contains survival times and prognostic factors for melanoma patients.
data("Melanoma_df")
# Dataset overview
str(Melanoma_df)
# Create meaningful labels
Melanoma_df$status_label <- factor(Melanoma_df$status,
levels = c(1, 2, 3),
labels = c("Died from melanoma",
"Alive",
"Died from other causes"))
Melanoma_df$sex_label <- factor(Melanoma_df$sex,
levels = c(0, 1),
labels = c("Female", "Male"))
Melanoma_df$ulcer_label <- factor(Melanoma_df$ulcer,
levels = c(0, 1),
labels = c("No", "Yes"))
# Summary of survival times
summary(Melanoma_df$time)
table(Melanoma_df$status_label)
Kaplan-Meier Analysis by Sex
# In jamovi:
# 1. Select Analyses → jSurvival → Survival Analysis
# 2. Set 'time' as survival time
# 3. Set 'status' as event (with 1 = died from melanoma)
# 4. Add 'sex_label' as grouping factor
# 5. Enable confidence intervals
# 6. Request median survival times
# 7. Add risk table
Cox Proportional Hazards Model
Analyze multiple prognostic factors simultaneously:
# In jamovi:
# 1. Select Analyses → jSurvival → Survival Analysis
# 2. Set up time and status as before
# 3. Add covariates: age, sex, thickness, ulcer
# 4. Enable Cox regression
# 5. Request hazard ratios with 95% CI
# 6. Check proportional hazards assumption
Competing Risks Analysis
Since patients can die from other causes:
# In jamovi:
# 1. Select Analyses → jSurvival → Competing Risks
# 2. Set 'time' as survival time
# 3. Set 'status' with:
# - 0 = censored
# - 1 = died from melanoma
# - 3 = died from other causes
# 4. Analyze by ulceration status
# 5. Request cumulative incidence plots
Example 2: Leukemia Treatment Comparison
data("LeukemiaSurvival_df")
# Dataset structure
str(LeukemiaSurvival_df)
# Create treatment labels
LeukemiaSurvival_df$treatment <- factor(LeukemiaSurvival_df$rx,
levels = c(0, 1),
labels = c("Control", "Treatment"))
# Summary by treatment
table(LeukemiaSurvival_df$treatment, LeukemiaSurvival_df$status)
Treatment Effect Analysis
# In jamovi:
# 1. Select Analyses → jSurvival → Survival Analysis
# 2. Time variable: 'time'
# 3. Event variable: 'status'
# 4. Group by: 'treatment'
# 5. Enable log-rank test
# 6. Add stratification by 'sex' if needed
# 7. Request survival probability table at key timepoints
Example 3: Prostate Cancer with Multiple Factors
data("ProstateSurvival_df")
# Large dataset overview
dim(ProstateSurvival_df)
table(ProstateSurvival_df$grade, ProstateSurvival_df$stage)
# Survival overview
summary(ProstateSurvival_df$survTime)
table(ProstateSurvival_df$status)
Stratified Analysis
# In jamovi:
# 1. Select Analyses → jSurvival → Survival Analysis
# 2. Basic setup with survTime and status
# 3. Compare by 'grade' (moderate vs poor)
# 4. Stratify by 'stage' and 'ageGroup'
# 5. Enable subset analysis for specific age groups
# 6. Request 1, 3, and 5-year survival rates
Example 4: Lung Cancer NCCTG Trial
data("NCCTGLungCancer_df")
# Dataset with missing values
str(NCCTGLungCancer_df)
# Performance status distribution
table(NCCTGLungCancer_df$ph.ecog, useNA = "ifany")
Example 5: Ovarian Cancer Trial
Advanced Features
Practical Workflow Example
# Complete survival analysis workflow:
# 1. Data Preparation
# - Import data
# - Create survival time and event variables
# - Handle competing events
# 2. Descriptive Analysis
# - Summary of follow-up times
# - Event rates by group
# - Missing data patterns
# 3. Kaplan-Meier Analysis
# - Overall survival curves
# - Stratified analyses
# - Median survival times
# 4. Cox Regression
# - Univariate screening
# - Multivariate model
# - Assumption checking
# 5. Advanced Analyses
# - Competing risks if applicable
# - Time-dependent covariates
# - Sensitivity analyses
# 6. Reporting
# - Generate publication figures
# - Create summary tables
# - Export results
Best Practices
- Define Events Clearly: Specify primary endpoint
- Handle Censoring: Document reasons for censoring
- Check Assumptions: Test proportional hazards
- Report Fully: Follow STROBE guidelines
- Consider Competing Risks: Especially in elderly populations
Conclusion
The jSurvival module provides comprehensive tools for analyzing
time-to-event data in oncology research. Combined with the
OncoDataSets
package, researchers can:
- Perform standard and advanced survival analyses
- Handle complex scenarios like competing risks
- Generate publication-quality figures
- Develop and validate prognostic models
References
- OncoDataSets package: https://cran.r-project.org/package=OncoDataSets
- jSurvival documentation: https://www.serdarbalci.com/jsurvival/
- Survival analysis in R: https://cran.r-project.org/package=survival