Movatterモバイル変換


[0]ホーム

URL:


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 DavisonORCID iD [aut, cre], Brad Kievit [aut], Maple Health Group, LLC [cph, fnd]
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

logo

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:

Other contributors:

See Also

Useful links:


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_adtte

Format

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

ggsurvfit::adtte


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_bc

Format

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

flexsurv::bc


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_lung

Format

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

survival::lung


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 indata containing thetime-to-event information.

event

The name of the column indata indicating whether theevent of interest occurred.

predict_by

(Optional) The name of the column indata definingthe prediction variable.

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 isc("exp", "gamma", "gengamma", "gompertz", "llogis", "lnorm", "weibull") which applies to flexsurv-related engines.

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 isc(1, 2, 3) to test differentnumbers.

scale

(Optional) A character vector specifying the scale parameter(s)for spline-based models. Options are "hazard", "odds", and "normal".Default is"hazard".

add_time_0

Optional. Usessurvival::survfit0() to add a startingtime of 0 to the KM survfit object. This may be useful for plotting the KMat a subsequent stage (in surv_plots). Default is TRUE.

...

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")models

Generate 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 indata containing thetime-to-event information.

event

The name of the column indata indicating whether theevent of interest occurred.

group

(Optional) The name of the column indata defining thegrouping variable. Default isNULL.

group_labels

Optional character vector containing the names ofthe strata (default is NULL). Provide in a consistent order withlevels(as.factor(data$group)).

just_km

Logical. IfTRUE, only the Kaplan-Meier estimates arereturned. Default isFALSE.

...

(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_results

Extract 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 classcox.zph produced by thecox.zphfunction, representing the Schoenfeld residuals of a Cox proportionalhazards model.

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 indata containing the time-to-event data.

event

The column name indata containing the event indicator data.

group

Optional. The column name indata containing the groupindicator data.

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 classfit_models

eval_time

Time points at which to evaluate the survival function.Default isNULL.

km_include

Logical value indicating whether to include Kaplan-Meiersurvival data. Default isTRUE.

subtitle_include

Logical value indicating whether to include asubtitle in the plot. Default isTRUE.

add_plotly

Logical value indicating whether to add plotlyinteractivity. Default isFALSE.

...

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

legend_position

Position of the legend in the plot. Default is"top".

plot_theme

ggplot2 theme for the plot. Default istheme_easysurv().

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

risktable_symbols

Logical value indicating whether to include symbolsinstead of text to label risk table strata. Default isTRUE.

median_line

Logical value indicating whether to include a linerepresenting the median survival time. Default isTRUE.

legend_position

Position of the legend in the plot. Default is"top".

plot_theme

ggplot2 theme for the plot. Default istheme_easysurv().

risktable_theme

ggplot2 theme for the risk table. Default istheme_risktable_easysurv().

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 columnstime,residual,transform, andvariable.

hline

Logical. IfTRUE, a horizontal line is added to the plot.Default isTRUE.

sline

Logical. IfTRUE, a smooth line is added to the plot.Default isTRUE.

sline_se

Logical. IfTRUE, confidence intervals are displayed aroundthe smooth line. Default isTRUE.

hline_col

Color of the horizontal line. Default is"#F8766D" (red).

hline_size

Line width of the horizontal line. Default is1.

hline_alpha

Transparency of the horizontal line. Default is1.

hline_yintercept

Y-intercept for the horizontal line. Default is0.

hline_lty

Line type for the horizontal line. Default is"dashed".

sline_col

Color of the smooth line. Default is"#00BFC4" (blue).

sline_size

Line width of the smooth line. Default is1.

sline_alpha

Transparency of the smooth line. Default is0.2.

sline_lty

Line type for the smooth line. Default is"dashed".

point_col

Color of the points representing residuals. Default is"black".

point_size

Size of the points representing residuals. Default is1.

point_shape

Shape of the points representing residuals. Default is19.

point_alpha

Transparency of the points representing residuals. Defaultis1.

plot_theme

A ggplot2 theme for the plot. Default isggplot2::theme_bw().

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 classfit_models

eval_time

(Optional) A vector of evaluation time points for generatingpredictions. Default isNULL, which if left as NULL, generates asequence from 0 to 5 times the maximum observed time.

type

A character vector indicating the type of predictions togenerate. Default isc("survival", "hazard").

...

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 isNULL, which if left as NULL, generates asequence from 0 to 5 times the maximum observed time.

km_include

A logical indicating whether to include Kaplan-Meierestimates in the plot outputs. Default isTRUE.

subtitle_include

A logical indicating whether to include the subtitle.Default isTRUE. The subtitle is the name of the group.

add_plotly

A logical indicating whether to add interactive plotlyoutputs for each plot. Default isFALSE.

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 classfit_models

...

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")models

Print methods forget_km()

Description

Print methods forget_km()

Usage

## S3 method for class 'get_km'print(x, ...)

Arguments

x

An object of classget_km

...

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 classinspect_surv_data

...

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 classpredict_and_plot

...

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 classtest_ph

...

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_results

Launch 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 indata containing thetime-to-event information.

event

The name of the column indata indicating whether theevent of interest occurred.

group

The name of the column indata defining the groupingvariable.

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_results

Plot 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())fit

Export 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)

[8]ページ先頭

©2009-2025 Movatter.jp