Creates a survfit object for day and status, then fits a survival curve by condition.

fit_surv(
  df_isurv,
  formula = "Surv(day, status) ~ condition",
  as_data_frame = FALSE
)

Arguments

df_isurv

A data.frame object of survival data with one individual per row. If starting with bulk survival data (multiple observations per row), run get_indiv_surv() first.

formula

A character string passed to a survival::survfit.formula. Default: "Surv(day, status) ~ condition"

as_data_frame

If FALSE, returns a survfit object from the survival package. If TRUE, returns it in a data.frame format. Default: FALSE

Value

A survival::survfit() object. If as_data_frame = TRUE, returns it in a data.frame format. Default: FALSE

Details

Call: survival::survfit(Surv(day, status) ~ condition, data = df_isurv)}

Examples

# Convert bulk survival to individual survival
df_isurv <- get_indiv_surv(sample_data, sample_order = c("WT", "Drug1", "Drug2"))
#> Joining with `by = join_by(x, condition, day, sex, status)`

# Fit survival object with the default call (condition)
surv_fit <- fit_surv(df_isurv)
#> 
#> call: formula = Surv(day, status) ~ condition
surv_fit
#> Call: survfit(formula = Surv(day, status) ~ condition, data = df_isurv)
#> 
#>                  n events median 0.95LCL 0.95UCL
#> condition=WT    50     47   20.0      19      21
#> condition=Drug1 50     46    4.5       4       6
#> condition=Drug2 50     42   33.0      32      35

# Fit survival object with custom call (condition + sex)
surv_fit <- fit_surv(df_isurv, formula = "Surv(day, status) ~ sex + condition")
#> 
#> call: formula = Surv(day, status) ~ sex + condition
surv_fit
#> Call: survfit(formula = Surv(day, status) ~ sex + condition, data = df_isurv)
#> 
#>                         n events median 0.95LCL 0.95UCL
#> sex=F, condition=WT    38     38   20.5      20      22
#> sex=F, condition=Drug1  3      2   13.0      11      NA
#> sex=F, condition=Drug2 33     32   35.0      33      36
#> sex=M, condition=WT    12      9    4.0       3      NA
#> sex=M, condition=Drug1 47     44    4.0       3       6
#> sex=M, condition=Drug2 17     10   28.0      27      NA