| Type: | Package |
| Title: | Simplify Survival Data Analysis and Model Fitting |
| Version: | 2.0.2 |
| Description: | Inspect survival data, plot Kaplan-Meier curves, assess the proportional hazards assumption, fit parametric survival models, predict and plot survival and hazards, and export the outputs to 'Excel'. A simple interface for fitting survival models using flexsurv::flexsurvreg(), flexsurv::flexsurvspline(), flexsurvcure::flexsurvcure(), and survival::survreg(). |
| License: | MIT + file LICENSE |
| URL: | https://github.com/Maple-Health-Group/easysurv,https://maple-health-group.github.io/easysurv/ |
| BugReports: | https://github.com/Maple-Health-Group/easysurv/issues |
| Depends: | R (≥ 4.1.0) |
| Imports: | bshazard, censored, cli, data.table, dplyr, flexsurv,flexsurvcure, ggplot2, ggsurvfit (≥ 1.2.0), openxlsx, parsnip,plotly, purrr, rlang, scales, stats, survival, tibble, tidyr,usethis, utils |
| Suggests: | knitr, rmarkdown, spelling, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| Config/Needs/website: | r-lib/asciicast |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| Language: | en-US |
| LazyData: | true |
| RoxygenNote: | 7.3.2 |
| NeedsCompilation: | no |
| Packaged: | 2025-10-08 10:34:50 UTC; NiallDavison |
| Author: | Niall Davison |
| Maintainer: | Niall Davison <niall.davison@maplehealthgroup.com> |
| Repository: | CRAN |
| Date/Publication: | 2025-10-08 11:30:02 UTC |
easysurv: Simplify Survival Data Analysis and Model Fitting
Description

Inspect survival data, plot Kaplan-Meier curves, assess the proportional hazards assumption, fit parametric survival models, predict and plot survival and hazards, and export the outputs to 'Excel'. A simple interface for fitting survival models using flexsurv::flexsurvreg(), flexsurv::flexsurvspline(), flexsurvcure::flexsurvcure(), and survival::survreg().
Author(s)
Maintainer: Niall Davisonniall.davison@maplehealthgroup.com (ORCID)
Authors:
Brad Kievitbrad.kievit@maplehealthgroup.com
Other contributors:
Maple Health Group, LLC [copyright holder, funder]
See Also
Useful links:
Report bugs athttps://github.com/Maple-Health-Group/easysurv/issues
Formatted Copy ofggsurvfit::adtte
Description
BackgroundThe example simulated data set is based on large phase III clinical trials inbreast cancer such as the ALTTO trialdoi:10.1200/JCO.2015.62.1797.The example trial aims to determine if a combination of two therapiestablemab (T) plus vismab (V) improves outcomes for metastatic human epidermalgrowth factor 2-positive breast cancer and increases the pathologic completeresponse in the neoadjuvant setting (i.e. treatment given as a first step toshrink a tumor before the main treatment or surgery).
The trial has four treatment arms, patients with centrally confirmed humanepidermal growth factor 2-positive early breast cancer were randomly assignedto 1 year of adjuvant therapy with V, T, their sequence (T to V), or theircombination (T+V) for 52 weeks.
The primary end point was progression-free survival (PFS) as defined byCancer.gov: '"the length of time during and after the treatment of a disease,such as cancer, that a patient lives with the disease but it does not getworse. In a clinical trial, measuring the progression-free survival is oneway to see how well a new treatment works"'.
A number of baseline measurements (taken at randomization) are also includedsuch as age, hormone receptor status and prior radiotherapy treatment.
Additional details on reasons for study discontinuation and censoringevent description are also included.
The data set adopts an abridged version of the CDISC ADaM ADTTEtime to event data model. See here for more info on CDISC ADaM data standardshttps://www.cdisc.org/standards/foundational/adam and specifically theADTTE time to event data model herehttps://www.cdisc.org/standards/foundational/adam/adam-basic-data-structure-bds-time-event-tte-analyses-v1-0.
Usage
easy_adtteFormat
The data set contains the following variables:
- STUDYID
The study identifier. A code unique to the clinical trial
- SUBJID
subject identifier. Numeric ID unique to each patient
- USUBJID
unique subject identifier. Text ID combining study and patient IDs
- AGE
age at randomisation (years)
- STR01
Hormone receptor status at randomisation
- STR01N
Hormone receptor positive (Numeric)
- STR01L
Hormone receptor positive (Long format)
- STR02
Prior Radiotherapy at randomisation
- STR02N
Prior Radiotherapy at randomisation (Numeric)
- STR02L
Prior Radiotherapy at randomisation (Long format)
- TRT01P
Planned treatment assigned at randomisation
- TRT01PN
Planned treatment assigned at randomisation (Numeric)
- PARAM
Analysis parameter: Progression free survival
- PARAMCD
Analysis parameter code
- AVAL
Analysis value (time to event (years)
- CNSR
Censoring (0 = Event, 1 = Censored)
- EVNTDESC
Event description
- CNSDTDSC
Censoring description
- DCTREAS
Discontinuation from study reason
Source
Formatted Copy offlexsurv::bc
Description
This is a copy of the bc data set exported by the flexsurvpackage. This data set, however, has column labels assigned.
Usage
easy_bcFormat
The data set contains the following variables:
- censrec
0 = Censored, 1 = Dead
- rectime
Time of censoring or death in days
- group
Prognostic group: Good, Medium, or Poor
- recyrs
Time of censoring or death in years
Source
Formatted Copy ofsurvival::lung
Description
This is a copy of the lung data set exported by the survivalpackage. This data set, however, has column labels assigned and time inmonths.
Usage
easy_lungFormat
The data set contains the following variables:
- inst
Institution code
- time
Survival time, months
- status
Censoring status, 1 = censored, 2 = dead
- age
Age
- sex
Sex, 1 = Male, 2 = Female
- ph.ecog
ECOG Performance Status (Physician)
- ph.karno
Karnofsky performance score (Physician)
- pat.karno
Karnofsky performance score (Patient)
- meal.cal
Calories consumed
- wt.loss
Weight loss, lbs
Source
Fit Survival Models
Description
Fits survival models to the provided data using the specified engine andreturns various outputs including model parameters, goodness of fit, andestimates of median survival.
Usage
fit_models( data, time, event, predict_by = NULL, covariates = NULL, dists = c("exp", "gamma", "gengamma", "gompertz", "llogis", "lnorm", "weibull"), engine = "flexsurv", k = c(1, 2, 3), scale = "hazard", add_time_0 = TRUE, ...)Arguments
data | A data frame containing the survival data. |
time | The name of the column in |
event | The name of the column in |
predict_by | (Optional) The name of the column in |
covariates | (Optional) A character vector specifying the names ofcovariates to be included in the model. |
dists | (Optional) A character vector specifying the distribution(s) tobe fitted. When the engine parameter is set to "flexsurv", options are "exp","exponential", "gamma", "genf", "genf.orig", "gengamma", "gengamma.orig","gompertz", "llogis", "lnorm", "lognormal", "weibull", "weibullPH". When the engine parameter is set to "flexsurvcure", options are "exp","gamma", "gengamma", "gompertz", "llogis", "lnorm", "weibull". When the engine parameter is set to "flexsurvspline", dists are ignored infavor of k and scale parameters. When the engine parameter is set to "survival", options are "exponential","extreme", "gaussian", "loggaussian" (same as lognormal), "logistic","lognormal", "rayleigh", "weibull". Default is |
engine | (Optional) The survival analysis engine to be used.Options are "flexsurv", "flexsurvcure", "flexsurvspline", and "survival".Default is "flexsurv".
|
k | (Optional) A numeric vector specifying the number of knots forspline-based models. Default is |
scale | (Optional) A character vector specifying the scale parameter(s)for spline-based models. Options are "hazard", "odds", and "normal".Default is |
add_time_0 | Optional. Uses |
... | Additional arguments just to catch them and avoid errors. |
Value
A list containing information about the fit_models() call, thedistributions attempted, goodness of fit, fit averages, and cure fractions(if applicable).
Examples
models <- fit_models( data = easysurv::easy_bc, time = "recyrs", event = "censrec", predict_by = "group", covariates = "group")modelsGenerate Kaplan-Meier estimates
Description
Calculates Kaplan-Meier estimates for survival data and returns summarystatistics, plots, and additional outputs.
Usage
get_km( data, time, event, group = NULL, group_labels = NULL, just_km = FALSE, ...)Arguments
data | A data frame containing the survival data. |
time | The name of the column in |
event | The name of the column in |
group | (Optional) The name of the column in |
group_labels | Optional character vector containing the names ofthe strata (default is NULL). Provide in a consistent order with |
just_km | Logical. If |
... | (Optional) Parameters to pass to ggsurvfit. |
Value
A list containing Kaplan-Meier estimates, summary statistics, andplots.
Examples
km_results <- get_km( data = easysurv::easy_bc, time = "recyrs", event = "censrec", group = "group", risktable_symbols = FALSE)km_resultsExtract Schoenfeld Residuals
Description
This function extracts Schoenfeld residuals from a fittedcox.zph objectand formats them into a tidy data frame.
Usage
get_schoenfeld(fit_zph)Arguments
fit_zph | An object of class |
Value
A tibble with the Schoenfeld residuals in long format, containingthe columns:
time | The time variable from the Cox model. |
transform | The transformation applied to the time variable. |
variable | The variable names from the Cox model for which residualsare calculated. |
residual | The Schoenfeld residuals for each variable at each timepoint. |
Examples
library(survival)test_fit <- survival::coxph(survival::Surv(time, status) ~ sex, data = lung)test_fit_zph <- survival::cox.zph(test_fit)get_schoenfeld(test_fit_zph)Inspect Survival Data
Description
Quickly inspect the survival data to ensure it is in the correct format.
Usage
inspect_surv_data(data, time, event, group = NULL)Arguments
data | A data frame containing the survival data. |
time | The column name in |
event | The column name in |
group | Optional. The column name in |
Value
A list containing tibbles that summarise the first few rows of thesurvival data, the sample sizes, the events, and median survival.
Examples
inspect_surv_data( data = easysurv::easy_bc, time = "recyrs", event = "censrec", group = "group")Plot method forfit_models
Description
Plot method forfit_models
Usage
## S3 method for class 'fit_models'plot( x, eval_time = NULL, km_include = TRUE, subtitle_include = TRUE, add_plotly = FALSE, ...)Arguments
x | An object of class |
eval_time | Time points at which to evaluate the survival function.Default is |
km_include | Logical value indicating whether to include Kaplan-Meiersurvival data. Default is |
subtitle_include | Logical value indicating whether to include asubtitle in the plot. Default is |
add_plotly | Logical value indicating whether to add plotlyinteractivity. Default is |
... | Additional arguments |
Value
A list containing predictions and plots for the survival and hazardsof models in afit_models object.
Examples
models <- fit_models( data = easysurv::easy_bc, time = "recyrs", event = "censrec", predict_by = "group", covariates = "group")plot(models)Cumulative Log Log Plot
Description
Generates a Cumulative Log Log survival curve plot usingggsurvfit::ggsurvfit() with customizable options.
Usage
plot_cloglog( fit, median_line = FALSE, legend_position = "top", plot_theme = theme_easysurv())Arguments
fit | Asurvival::survfit object representing thesurvival data. |
median_line | Logical value indicating whether to include a linerepresenting the median survival time. Default is |
legend_position | Position of the legend in the plot. Default is"top". |
plot_theme | ggplot2 theme for the plot. Default is |
Value
A ggplot object representing the cumulative log log plot.
Examples
library(ggsurvfit)fit <- survfit2(Surv(time, status) ~ surg, data = df_colon)plot_cloglog(fit)Plot Kaplan-Meier Data
Description
Generates a Kaplan-Meier survival curve plot usingggsurvfit::ggsurvfit() with customizable options.This function provides sensible defaults while allowing for customization.
Usage
plot_km( fit, risktable = TRUE, risktable_symbols = TRUE, median_line = TRUE, legend_position = "top", plot_theme = theme_easysurv(), risktable_theme = theme_risktable_easysurv())Arguments
fit | Asurvival::survfit object representing thesurvival data. |
risktable | Logical value indicating whether to include a risk tablebelow the plot. Default is |
risktable_symbols | Logical value indicating whether to include symbolsinstead of text to label risk table strata. Default is |
median_line | Logical value indicating whether to include a linerepresenting the median survival time. Default is |
legend_position | Position of the legend in the plot. Default is"top". |
plot_theme | ggplot2 theme for the plot. Default is |
risktable_theme | ggplot2 theme for the risk table. Default is |
Value
A ggplot object representing the Kaplan-Meier survival curve plot.
Examples
library(ggsurvfit)fit <- survfit2(Surv(time, status) ~ surg, data = df_colon)plot_km(fit, risktable_symbols = FALSE)Plot Schoenfeld Residuals
Description
Plot the residuals generated by theget_schoenfeld function.This function creates a visual representation of Schoenfeld residuals from aCox proportional hazards model.It allows for customization of the plot, including the addition of horizontaland smoothed lines, and styling of points and plot elements.
Usage
plot_schoenfeld( residuals, hline = TRUE, sline = TRUE, sline_se = TRUE, hline_col = "#F8766D", hline_size = 1, hline_alpha = 1, hline_yintercept = 0, hline_lty = "dashed", sline_col = "#00BFC4", sline_size = 1, sline_alpha = 0.2, sline_lty = "dashed", point_col = "black", point_size = 1, point_shape = 19, point_alpha = 1, plot_theme = ggplot2::theme_bw())Arguments
residuals | A data frame containing the Schoenfeld residuals, typicallywith columns |
hline | Logical. If |
sline | Logical. If |
sline_se | Logical. If |
hline_col | Color of the horizontal line. Default is |
hline_size | Line width of the horizontal line. Default is |
hline_alpha | Transparency of the horizontal line. Default is |
hline_yintercept | Y-intercept for the horizontal line. Default is |
hline_lty | Line type for the horizontal line. Default is |
sline_col | Color of the smooth line. Default is |
sline_size | Line width of the smooth line. Default is |
sline_alpha | Transparency of the smooth line. Default is |
sline_lty | Line type for the smooth line. Default is |
point_col | Color of the points representing residuals. Default is |
point_size | Size of the points representing residuals. Default is |
point_shape | Shape of the points representing residuals. Default is |
point_alpha | Transparency of the points representing residuals. Defaultis |
plot_theme | A ggplot2 theme for the plot. Default is |
Value
A ggplot object representing the plot of Schoenfeld residuals.
Examples
library(survival)test_fit <- survival::coxph(survival::Surv(time, status) ~ sex, data = lung)test_fit_zph <- survival::cox.zph(test_fit)plot_schoenfeld(get_schoenfeld(test_fit_zph))Predict method forfit_models
Description
Predict method forfit_models
Usage
## S3 method for class 'fit_models'predict(object, eval_time = NULL, type = c("survival", "hazard"), ...)Arguments
object | An object of class |
eval_time | (Optional) A vector of evaluation time points for generatingpredictions. Default is |
type | A character vector indicating the type of predictions togenerate. Default is |
... | Additional arguments |
Value
A list of predictions for each model in thefit_models object.
Examples
models <- fit_models( data = easysurv::easy_bc, time = "recyrs", event = "censrec", predict_by = "group", covariates = "group")predict(models)Predict and Plot Fitted Models
Description
This function generates survival and hazard predictions and plots for eachmodel in afit_models object. Optionally, interactiveplotlyoutputs can be added for each plot.
Usage
predict_and_plot( fit_models, eval_time = NULL, km_include = TRUE, subtitle_include = TRUE, add_plotly = FALSE)Arguments
fit_models | An object returned from fit_models. |
eval_time | (Optional) A vector of evaluation time points for generatingpredictions. Default is |
km_include | A logical indicating whether to include Kaplan-Meierestimates in the plot outputs. Default is |
subtitle_include | A logical indicating whether to include the subtitle.Default is |
add_plotly | A logical indicating whether to add interactive plotlyoutputs for each plot. Default is |
Value
A list of predictions and plots for each model in thefit_models object.
Examples
models <- fit_models( data = easysurv::easy_bc, time = "recyrs", event = "censrec", predict_by = "group")predict_and_plot(models)Print methods forfit_models()
Description
Print methods forfit_models()
Usage
## S3 method for class 'fit_models'print(x, ...)Arguments
x | An object of class |
... | Additional arguments |
Value
A print summary of thefit_models object.
Examples
models <- fit_models( data = easysurv::easy_bc, time = "recyrs", event = "censrec", predict_by = "group", covariates = "group")modelsPrint methods forget_km()
Description
Print methods forget_km()
Usage
## S3 method for class 'get_km'print(x, ...)Arguments
x | An object of class |
... | Additional arguments |
Value
The summary of the Kaplan-Meier estimates, printed via the console.
Examples
km_results <- get_km( data = easysurv::easy_bc, time = "recyrs", event = "censrec", group = "group", risktable_symbols = FALSE)print(km_results)Print methods forinspect_surv_data()
Description
Print methods forinspect_surv_data()
Usage
## S3 method for class 'inspect_surv_data'print(x, ...)Arguments
x | An object of class |
... | Additional arguments |
Value
A print summary of theinspect_surv_data object.
Print methods forpredict_and_plot()
Description
Print methods forpredict_and_plot()
Usage
## S3 method for class 'predict_and_plot'print(x, ...)Arguments
x | An object of class |
... | Additional arguments |
Value
A print summary of thepredict_and_plot object.
Examples
models <- fit_models( data = easysurv::easy_bc, time = "recyrs", event = "censrec", predict_by = "group")predict_and_plot(models)Print methods fortest_ph()
Description
Print methods fortest_ph()
Usage
## S3 method for class 'test_ph'print(x, ...)Arguments
x | An object of class |
... | Additional arguments |
Value
A print summary of thetest_ph object.
Examples
ph_results <- test_ph( data = easysurv::easy_bc, time = "recyrs", event = "censrec", group = "group")ph_resultsLaunch Example Survival Analysis Script using the easy_lung Data Set
Description
This function launches an example script for starting survival analysisusing the easysurv package. The script uses a modified version of thelung data set exported from the survival package. The code is inspired byusethis::use_template() but modified to work outside the context ofan .RProj or package.
Usage
quick_start(output_file_name = NULL)Arguments
output_file_name | Optional. A file name to use for the script. Defaultsto "easysurv_start.R" within a helper function. |
Value
A new R script file with example code.
Examples
quick_start()Launch Example Survival Analysis Script using the easy_bc Data Set
Description
This function launches an example script for starting survival analysisusing the easysurv package. The script uses a modified version of the bc dataset exported from the flexsurv package. The code is inspired byusethis::use_template() but modified to work outside the context of an.RProj or package.
Usage
quick_start2(output_file_name = NULL)Arguments
output_file_name | Optional. A file name to use for the script. Defaultsto "easysurv_start.R" within a helper function. |
Value
A new R script file with example code.
Examples
quick_start2()Launch Example Survival Analysis Script using the easy_adtte Data Set
Description
This function launches an example script for starting survival analysisusing the easysurv package. The script uses simulated phase III breastcancer trial data available from the ggsurvfit package.The code is inspired byusethis::use_template()but modified to work outside the context of an .RProj or package.
Usage
quick_start3(output_file_name = NULL)Arguments
output_file_name | Optional. A file name to use for the script. Defaultsto "easysurv_start.R" within a helper function. |
Value
A new R script file with example code.
Examples
quick_start3()Test Proportional Hazards Assumption
Description
Assesses the proportional hazards assumption for survival data using aCox proportional hazards model and related tests.
Usage
test_ph(data, time, event, group, plot_theme = theme_easysurv())Arguments
data | A data frame containing the survival data. |
time | The name of the column in |
event | The name of the column in |
group | The name of the column in |
plot_theme | The theme to be used for the plots. |
Value
A list containing plots and test results related to the assessmentof the proportional hazards assumption.
cloglog_plot | A plot of the log cumulative hazard function. If thelines are roughly parallel, this suggests that the proportional hazardsassumption holds." |
coxph_model | The coefficients from the Cox proportional hazardsmodel. The exp(coef) column shows the hazard ratio. |
survdiff | The results of the log-rank test for differences insurvival curves between groups. A p-value less than 0.05 suggests thatsurvival differences between groups are statistically significant. |
coxph_test | The results of the proportional hazards assumption test.A p-value less than 0.05 suggests that the proportional hazards assumptionmay be violated. |
schoenfeld_plot | A plot of the Schoenfeld residuals. A flat smoothedline close to zero supports the proportional hazards assumption. A non-flatsmoothed line with a trend suggests the proportional hazards assumption isviolated. |
Examples
ph_results <- test_ph( data = easysurv::easy_bc, time = "recyrs", event = "censrec", group = "group")ph_resultsPlot Theme for easysurv Survival and Hazard Plots
Description
Plot Theme for easysurv Survival and Hazard Plots
Usage
theme_easysurv()Value
A ggplot2 theme object.
Examples
library(ggsurvfit)fit <- survfit2(Surv(time, status) ~ surg, data = df_colon)fit |> ggsurvfit() + theme_easysurv()Plot Theme for easysurv Risk Tables
Description
To be used withggsurvfit::add_risktable().
Usage
theme_risktable_easysurv()Value
A list containing a ggplot2 theme object.
Examples
library(ggsurvfit)fit <- survfit2(Surv(time, status) ~ surg, data = df_colon)fit <- fit |> ggsurvfit() + theme_easysurv() + add_risktable(theme = theme_risktable_easysurv())fitExport easysurv output to Excel viaopenxlsx
Description
Export easysurv output to Excel viaopenxlsx
Usage
write_to_xl(wb, object)Arguments
wb | A Workbook object containing a worksheet |
object | The output of an easysurv command |
Value
An Excel workbook with the easysurv output.
Examples
km_results <- get_km( data = easysurv::easy_bc, time = "recyrs", event = "censrec", group = "group", risktable_symbols = FALSE)wb <- openxlsx::createWorkbook()## Not run: write_to_xl(wb, km_results)openxlsx::saveWorkbook(wb, "km_results.xlsx", overwrite = TRUE)openxlsx::openXL("km_results.xlsx")## End(Not run)