Skip to content

Commit

Permalink
Add a type = "cloglog" for log minus log survival plots (#195)
Browse files Browse the repository at this point in the history
* Adding a type = "cloglog" to tidysurvfit() and ggsurvfit() to plot log minus log survival curves

* Add documentation for cloglog

* Solve undefined global functions and variables

* Correct visible binding

* doc update

* doc update

* updates

* more updates

* Update R-CMD-check.yaml

* Update NEWS.md

* Update NEWS.md

* Update DESCRIPTION

* more updates

---------

Co-authored-by: Daniel Sjoberg <danield.sjoberg@gmail.com>
  • Loading branch information
avishaitsur and ddsjoberg authored May 8, 2024
1 parent d68d7ce commit ef4fc45
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 160 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ jobs:
- {os: macOS-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}

# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
# - {os: ubuntu-latest, r: 'oldrel-4'}
- {os: ubuntu-latest, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ggsurvfit
Title: Flexible Time-to-Event Figures
Version: 1.0.0.9002
Version: 1.0.0.9003
Authors@R: c(
person("Daniel D.", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0003-0862-2018")),
Expand Down
10 changes: 6 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# ggsurvfit (development version)

* For multi-state models created with `survfit()`, the y-axis label is now "Probability in State". (#205)

* Updated legend position syntax to account for changes in {ggplot2} v3.5.0.
* We now allow for negative follow-up times in `tidy_survfit()` (and subsequently `ggsurvfit()`). When negative follow-up times are present users should specify `survfit(start.time)` and we print a note to this effect when not set. (#192)

* The `tidy_survfit()` (and subsequently `ggsurvfit()`) now honor the `survfit(start.time)` if specified. (#192)

* We now allow for negative follow-up times in `tidy_survfit()` (and subsequently `ggsurvfit()`). When negative follow-up times are present users should specify `survfit(start.time)` and we print a note to this effect when not set. (#192)
* Updated legend position syntax to account for changes in {ggplot2} v3.5.0.

* As of {survival} v3.6-4, the number censored are now returned as a matrix for multi-state models (i.e. competing risks models). The `tidy_survfit()` function has been updated to account for this new structure and the minimum version of {survival} has been increased to the latest version. (#199)

* For non-competing risks multi-state models created with `survfit()`, the y-axis label is now "Probability in State". (#205)

* Added the "`cloglog`" transformation option to `ggsurvfit(type)` and `tidy_survfit(type)`. (#194)

# ggsurvfit 1.0.0

* By default, a model plot created with `ggsurvfit()` or `ggcuminc()` uses the color aesthetic to plot curves by the stratifying variable(s), and further, `ggcuminc()` uses the linetype aesthetic for plots that contain multiple outcomes (i.e. competing events). We now introduce the global option `"ggsurvfit.switch-color-linetype"` to switch these defaults, giving users more flexibility over the output figures. Furthermore, when the `linetype_aes=` argument is called in a situation when it does not apply, it will be silently ignored (previously, an error message _may_ have been thrown). (#166)
Expand Down
2 changes: 1 addition & 1 deletion R/ggcuminc.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#'
#' @section Details:
#'
#' *Why do we not use `cmprsk::cuminc()`?*
#' *Why not use `cmprsk::cuminc()`?*
#'
#' The implementation of `cmprsk::cuminc()` does not provide the data required
#' to construct the risk table. Moreover, the `tidycmprsk::cuminc()` has a
Expand Down
14 changes: 9 additions & 5 deletions R/tidy_survfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
#' @param type type of statistic to report.
#' Available for Kaplan-Meier estimates only.
#' Default is `"survival"`.
#' Must be one of the following:
#' Must be one of the following or a function:
#' ```{r, echo = FALSE}
#' dplyr::tribble(
#' ~type, ~transformation,
#' '`"survival"`', '`x`',
#' '`"risk"`', '`1 - x`',
#' '`"cumhaz"`', '`-log(x)`',
#' '`"cloglog"`', '`log(-log(x))`',
#' ) %>%
#' knitr::kable()
#' ```
Expand All @@ -31,7 +32,7 @@
#' tidy_survfit()
tidy_survfit <- function(x,
times = NULL,
type = c("survival", "risk", "cumhaz")) {
type = c("survival", "risk", "cumhaz", "cloglog")) {
# check inputs ---------------------------------------------------------------
if (!inherits(x, "survfit")) {
cli_abort(c("!" = "Argument {.code x} must be class {.cls survfit}.",
Expand Down Expand Up @@ -180,13 +181,14 @@ tidy_survfit <- function(x,
risk = function(y) 1 - y,
# survfit object contains an estimate for Cumhaz and SE based on Nelson-Aalen with or without correction for ties
# However, no CI is calculated automatically. For plotting, the MLE estimator is used for convenience.
cumhaz = function(y) -log(y)
cumhaz = function(y) -log(y),
cloglog = function(y) log(-log(y))
)
} else {
.transfun <- type
}
if (!rlang::is_function(.transfun)) {
cli_abort("The {.var type} argument must be one of {.val {c('survival', 'risk', 'cumhaz')}}, or a function.")
cli_abort("The {.var type} argument must be one of {.val {c('survival', 'risk', 'cumhaz', 'cloglog')}}, or a function.")
}

# transform estimates --------------------------------------------------------
Expand Down Expand Up @@ -218,6 +220,7 @@ tidy_survfit <- function(x,
!is.null(.env$survfit$transitions) ~ "Probability in State",
rlang::is_string(.env$type) && .env$type %in% "risk" ~ "Risk",
rlang::is_string(.env$type) && .env$type %in% "cumhaz" ~ "Cumulative Hazard",
rlang::is_string(.env$type) && .env$type %in% "cloglog" ~ "Log Minus Log Survival",
TRUE ~ rlang::expr_deparse(.transfun)
)
)
Expand Down Expand Up @@ -347,7 +350,8 @@ tidy_survfit <- function(x,
"survival" = "decreasing",
"cuminc" = "increasing",
"risk" = "increasing",
"cumhaz" = "increasing"
"cumhaz" = "increasing",
"cloglog" = "increasing"
)
}
else {
Expand Down
2 changes: 1 addition & 1 deletion man/ggcuminc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/ggsurvfit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 8 additions & 39 deletions man/stepribbon.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/tidy_survfit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ef4fc45

Please sign in to comment.