Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2.0.9000
Version: 1.2.0.9001
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ggsurvfit (development version)

* `Surv_CNSR()` updated to accept values `>= 1` as censoring values (according
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to add your @bundfussr if you'd like.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, done

to CDISC recommendation). (#271, @bundfussr)

# ggsurvfit 1.2.0

* Updates to account for changes in ggplot2 v4.0.0. (#241)
Expand Down
15 changes: 6 additions & 9 deletions R/Surv_CNSR.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' [survival](https://cran.r-project.org/package=survival) package.
#'
#' The `AVAL` and `CNSR` arguments are passed to
#' `survival::Surv(time = AVAL, event = 1 - CNSR, type = "right", origin = 0)`.
#' `survival::Surv(time = AVAL, event = CNSR == 0, type = "right", origin = 0)`.
#'
#' @section Details:
#'
Expand All @@ -29,11 +29,11 @@
#'
#' The CDISC ADaM ADTTE data model adopts a different coding convention for
#' the event/status indicator. Using this convention, the event/status variable
#' is named `'CNSR'` and uses the following coding: `censor = 1`, `status/event = 0`.
#' is named `'CNSR'` and uses the following coding: `censor >= 1`, `status/event = 0`.
#'
#' @param AVAL The follow-up time. The follow-up time is assumed to originate from zero.
#' When no argument is passed, the default value is a column/vector named `AVAL`.
#' @param CNSR The censoring indicator where `1=censored` and `0=death/event`.
#' @param CNSR The censoring indicator where `>=1=censored` and `0=death/event`.
#' When no argument is passed, the default value is a column/vector named `CNSR`.
#'
#' @return Object of class 'Surv'
Expand Down Expand Up @@ -68,17 +68,14 @@ Surv_CNSR <- function(AVAL, CNSR) {
stop("Expecting arguments 'AVAL' and 'CNSR' to be numeric.")
}

if (stats::na.omit(CNSR) %>% setdiff(c(0, 1)) %>%
{
!rlang::is_empty(.)
}) {
stop("Expecting 'CNSR' argument to be binary with values `0/1`.")
if (any(!rlang::is_integerish(CNSR)) || any(stats::na.omit(CNSR) < 0)) {
stop("Expecting 'CNSR' argument to be non-negative integer (>=0).")
}

if (any(AVAL < 0)) {
warning("Values of 'AVAL' are less than zero, which is likely a data error.")
}

# pass args to `survival::Surv()` --------------------------------------------
survival::Surv(time = AVAL, event = 1 - CNSR, type = "right", origin = 0)
survival::Surv(time = AVAL, event = CNSR == 0, type = "right", origin = 0)
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The package also includes gems for those using the [CDISC ADaM ADTTE v1.0](https

If columns `"PARAM"` or `"PARAMCD"` are present in the data frame passed to `survfit2()`, their values will be used to construct default labels in the `ggsurvfit()` figure.

The event indicator in ADTTE data sets is named `"CNSR"` and is coded in the opposite way the survival package expects outcomes---`1 = 'censored'` and `0 = 'event'`.
The event indicator in ADTTE data sets is named `"CNSR"` and is coded in the opposite way the survival package expects outcomes---`>=1 = 'censored'` and `0 = 'event'`.
This difference creates an opportunity for errors to be introduced in an analysis.
The **ggsurvfit** package exports a function called `Surv_CNSR()` to resolve this concern.
The function creates a survival object (e.g. `survival::Surv()`) that uses CDISC ADaM ADTTE coding conventions as the default values.
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ p +
)
```

<img src="man/figures/README-unnamed-chunk-2-1.png" width="100%" />
<img src="man/figures/README-unnamed-chunk-2-1.png" alt="" width="100%" />

## `survfit2()` vs `survfit()`

Expand Down Expand Up @@ -120,14 +120,14 @@ to `survfit2()`, their values will be used to construct default labels
in the `ggsurvfit()` figure.

The event indicator in ADTTE data sets is named `"CNSR"` and is coded in
the opposite way the survival package expects outcomes—`1 = 'censored'`
and `0 = 'event'`. This difference creates an opportunity for errors to
be introduced in an analysis. The **ggsurvfit** package exports a
function called `Surv_CNSR()` to resolve this concern. The function
creates a survival object (e.g. `survival::Surv()`) that uses CDISC ADaM
ADTTE coding conventions as the default values. The function can be used
in **ggsurvfit** as well as any other package that uses
`survival::Surv()`.
the opposite way the survival package expects
outcomes—`>=1 = 'censored'` and `0 = 'event'`. This difference creates
an opportunity for errors to be introduced in an analysis. The
**ggsurvfit** package exports a function called `Surv_CNSR()` to resolve
this concern. The function creates a survival object
(e.g. `survival::Surv()`) that uses CDISC ADaM ADTTE coding conventions
as the default values. The function can be used in **ggsurvfit** as well
as any other package that uses `survival::Surv()`.

``` r
survfit(Surv_CNSR() ~ 1, adtte)
Expand All @@ -139,4 +139,4 @@ survfit(Surv_CNSR() ~ 1, adtte)

## Related Packages

<img src="man/figures/README-gt-related-pkgs.png" width="100%" />
<img src="man/figures/README-gt-related-pkgs.png" alt="" width="100%" />
6 changes: 3 additions & 3 deletions man/Surv_CNSR.Rd

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

13 changes: 8 additions & 5 deletions tests/testthat/test-Surv_CNSR.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ test_that("The function is compatible with the survival package", {
test_that("The results of the estimation match between Surv_CNSR and Surv with inverted censoring", {
expect_equal(
with(adtte, Surv_CNSR()),
with(adtte, Surv(AVAL, 1 - CNSR))
with(adtte, Surv(AVAL, CNSR == 0))
)

km1 <- survfit2(formula = Surv_CNSR() ~ 1, data = adtte)
km2 <- survfit2(formula = Surv(AVAL, 1 - CNSR) ~ 1, data = adtte)
km2 <- survfit2(formula = Surv(AVAL, CNSR == 0) ~ 1, data = adtte)
km1$call <- km2$call <- km1$.Environment <- km2$.Environment <- NULL
expect_equal(km1, km2)

km1 <- survfit2(formula = Surv_CNSR() ~ STR01, data = adtte)
km2 <- survfit2(formula = Surv(AVAL, 1 - CNSR) ~ STR01, data = adtte)
km2 <- survfit2(formula = Surv(AVAL, CNSR == 0) ~ STR01, data = adtte)
km1$call <- km2$call <- km1$.Environment <- km2$.Environment <- NULL
expect_equal(km1, km2)
})
Expand Down Expand Up @@ -74,6 +74,9 @@ test_that("An error when the column name specified through CNSR in the environme
expect_error(survfit(Surv_CDISC(AVAL = time) ~ 1, data = survival::lung %>% dplyr::mutate(CNSR = as.character(status))))
})

test_that("An error when the column name specified through CNSR is not coded as 0/1", {
expect_error(survfit(Surv_CNSR(time, status) ~ 1, data = survival::lung))
test_that("An error when the column name specified through CNSR < 0", {
expect_error(survfit(
Surv_CNSR(time, status) ~ 1,
data = survival::lung %>% dplyr::mutate(status = status - 2)
))
})