Skip to contents

Compute p-value from survfit objects or parse it when provided by the user. Survival curves are compared using the log-rank test (default). Other methods can be specified using the argument method.

Usage

surv_pvalue(
  fit,
  data = NULL,
  method = "survdiff",
  test.for.trend = FALSE,
  combine = FALSE,
  ...
)

Arguments

fit

A survfit object. Can be also a list of survfit objects.

data

data frame used to fit survival curves. Can be also a list of data.

method

method to compute survival curves. Default is "survdiff" (or "log-rank"). Allowed values are one of:

  • "survdiff", log-rank;

  • "1": log-rank, LR; –> Regular log-rank test, sensitive to detect late differences.

  • "n": Gehan-Breslow (generalized Wilcoxon), GB; –> detect early differences.

  • "sqrtN": Tarone-Ware, TW; –> detect early differences.

  • "S1": Peto-Peto's modified survival estimate, PP; –> more robust than Tharone-Whare or Gehan-Breslow, detect early differences

  • "S2": modified Peto-Peto (by Andersen), mPP

  • "FH_p=1_q=1": Fleming-Harrington(p=1, q=1), FH

To specify method, one can use either the weights (e.g.: "1", "n", "sqrtN", ...), or the full name ("log-rank", "gehan-breslow", "Peto-Peto", ...), or the acronyme LR, GB, .... Case insensitive partial match is allowed.

To learn more about the mathematical background behind the different log-rank weights, read the following blog post on R-Addict: Comparing (Fancy) Survival Curves with Weighted Log-rank Tests

test.for.trend

logical value. Default is FALSE. If TRUE, returns the test for trend p-values. Tests for trend are designed to detect ordered differences in survival curves. That is, for at least one group. The test for trend can be only performed when the number of groups is > 2.

combine

logical value. Used only when fit is a list of survfit objects. If TRUE, combine the results for multiple fits.

...

other arguments including pval, pval.coord, pval.method.coord. These are only used internally to specify custom pvalue, pvalue and pvalue method coordinates on the survival plot. Normally, users don't need these arguments.

Value

Return a data frame with the columns (pval, method, pval.txt and variable). If additional arguments (pval, pval.coord, pval.method.coord, get_coord) are specified, then extra columns (pval.x, pval.y, method.x and method.y) are returned.

  • pval: pvalue

  • method: method used to compute pvalues

  • pval.txt: formatted text ready to use for annotating plots

  • pval.x, pval.y: x & y coordinates of the pvalue for annotating the plot

  • method.x, method.y: x & y coordinates of pvalue method

Examples


library(survival)

# Different survfits
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::
fit.null <- surv_fit(Surv(time, status) ~ 1, data = colon)

fit1 <- surv_fit(Surv(time, status) ~ sex, data = colon)

fit2 <- surv_fit(Surv(time, status) ~ adhere, data = colon)

fit.list <- list(sex = fit1, adhere = fit2)

# Extract the median survival
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::
surv_pvalue(fit.null)
#> Warning: There are no survival curves to be compared. 
#>  This is a null model.
#>   variable pval method pval.txt
#> 1            NA                

surv_pvalue(fit2, colon)
#>   variable         pval   method    pval.txt
#> 1   adhere 0.0002670768 Log-rank p = 0.00027

surv_pvalue(fit.list)
#> $sex
#>   variable      pval   method pval.txt
#> 1      sex 0.6107936 Log-rank p = 0.61
#> 
#> $adhere
#>   variable         pval   method    pval.txt
#> 1   adhere 0.0002670768 Log-rank p = 0.00027
#> 

surv_pvalue(fit.list, combine = TRUE)
#>       id variable         pval   method    pval.txt
#> 1    sex      sex 0.6107936361 Log-rank    p = 0.61
#> 2 adhere   adhere 0.0002670768 Log-rank p = 0.00027

# Grouped survfit
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::
fit.list2 <- surv_fit(Surv(time, status) ~ sex, data = colon,
                     group.by = "rx")

surv_pvalue(fit.list2)
#> $`rx.Obs::sex`
#>   variable      pval   method pval.txt
#> 1      sex 0.5337304 Log-rank p = 0.53
#> 
#> $`rx.Lev::sex`
#>   variable      pval   method pval.txt
#> 1      sex 0.2928911 Log-rank p = 0.29
#> 
#> $`rx.Lev+5FU::sex`
#>   variable         pval   method    pval.txt
#> 1      sex 0.0005623961 Log-rank p = 0.00056
#> 

# Get coordinate for annotion of the survival plots
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::
surv_pvalue(fit.list2, combine = TRUE, get_coord = TRUE)
#>                id variable         pval   method    pval.txt pval.x pval.y
#> 1     rx.Obs::sex      sex 0.5337303974 Log-rank    p = 0.53  64.28    0.2
#> 2     rx.Lev::sex      sex 0.2928911335 Log-rank    p = 0.29  66.58    0.2
#> 3 rx.Lev+5FU::sex      sex 0.0005623961 Log-rank p = 0.00056  66.18    0.2
#>   method.x method.y
#> 1    64.28      0.3
#> 2    66.58      0.3
#> 3    66.18      0.3