Skip to content

Commit

Permalink
Review of Joanna testing (#361)
Browse files Browse the repository at this point in the history
* Review of Joanna testing

estimate_cuminc
--------------
- Initialize data argument
- focus on arguments that are required for ADaM eg confint can be defined through ... Tidycmprisk should deal with confint variations
- add more informative messages
- Do we want to add an overall strata? We can put Overall instead of 1 inside the formula and then add a column strat99= Overall
- %||% is not defined. When strata is NULL then the formula becomes ...... ~ NULL in the final object without any error => used ifelse statement

testing
-------
- we need to focus on what the wrapper is doing, not on what the tidycmprisk function
 -- test arguments
 -- test excecuting surrounding the main function
 -- do not test how the main function works
- downstream processing of this object needs to be tested in the respective test files, not in the estimate function
- we expect tidycmprisk to do the heavy lifting and testing on the final object. We only verify wether the wrapper does not change the object. If it do

* Re-build README.Rmd

* review updates

* Update _pkgdown.yml

* adding `visR::` prefix in examples

* review updates from call

* Re-build README.Rmd

* update for conf.int

* Re-build README.Rmd

* redocument

Co-authored-by: shaesen2 <shaesen2@its.jnj.com>
Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: Daniel Sjoberg <danield.sjoberg@gmail.com>
  • Loading branch information
4 people authored May 2, 2022
1 parent e097964 commit e0a87f4
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 184 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/notebooks/libs
/notebooks/*.html
.Rproj.user
visR.Rproj
.Rbuildignore
inst/doc
.Rhistory
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Suggests:
rmarkdown,
rsconnect,
shiny,
gt (>= 0.1.0),
gt (>= 0.3.0),
forcats,
testthat (>= 2.1.0),
data.table,
Expand Down
6 changes: 3 additions & 3 deletions R/estimate_KM.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ estimate_KM <- function(

# Remove NA from the analysis --------------------------------------------

data <- as.data.frame(data)%>%
tidyr::drop_na(AVAL, CNSR, strata)
data <- as.data.frame(data) %>%
tidyr::drop_na(AVAL, CNSR)

if (!is.null(strata)){
data <- data%>%
data <- data %>%
tidyr::drop_na(any_of({{strata}}))
}

Expand Down
67 changes: 52 additions & 15 deletions R/estimate_cuminc.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' Column must be a factor and the first level indicates censoring, the
#' next level is the outcome of interest, and the remaining levels are the
#' competing events. Default is `"CNSR"`
#' @param conf.int Confidence internal level. Default is 0.95.
#' @param conf.int Confidence internal level. Default is 0.95. Parameter is passed to `tidycmprsk::cuminc(conf.level=)`
#' @param ... Additional argument passed to `tidycmprsk::cuminc()`
#' @inheritParams estimate_KM
#' @inheritParams visr
Expand All @@ -20,29 +20,66 @@
#' @export
#'
#' @examples
#' estimate_cuminc(
#' tidycmprsk::trial,
#' strata = "trt",
#' CNSR = "death_cr",
#' AVAL = "ttdeath"
#' ) %>%
#' visr() %>%
#' add_CI() %>%
#' add_risktable(statlist = c("n.risk", "cum.event"))

estimate_cuminc <- function(data
#' cuminc <-
#' visR::estimate_cuminc(
#' data = tidycmprsk::trial,
#' strata = "trt",
#' CNSR = "death_cr",
#' AVAL = "ttdeath"
#' )
#' cuminc
#'
#' cuminc %>%
#' visR::visr() %>%
#' visR::add_CI() %>%
#' visR::add_risktable(statlist = c("n.risk", "cum.event"))

estimate_cuminc <- function( data = NULL
,strata = NULL
,CNSR = "CNSR"
,AVAL = "AVAL"
,conf.int = 0.95
,...) {
# check for installation of tidycmprsk package


# check for installation of tidycmprsk package -------------------------
rlang::check_installed("tidycmprsk", version = "0.1.1")
dots <- rlang::dots_list(...)

# checking/prepping inputs ---------------------------------------------------
strata <- strata %||% "1" %>% paste(collapse = " + ")
# Validate data --------------------------------------------------------
if (is.null(data)) stop(paste0("Data can't be NULL."))
if (!is.numeric(conf.int)) stop(paste0("conf.int needs to be numeric."))
if (!(0 <= conf.int & conf.int <= 1)) stop(paste0("conf.int needs to between 0 and 1."))

# Validate columns -----------------------------------------------------
reqcols <- c(strata, CNSR, AVAL)

if (! all(reqcols %in% colnames(data))){
stop(paste0("Following columns are missing from `data`: ", paste(setdiff(reqcols, colnames(data)), collapse = " "), "."))
}

if (! is.numeric(data[[AVAL]])){
stop("Analysis variable (AVAL) is not numeric.")
}

if (! is.factor(data[[CNSR]])){
stop("Censor variable (CNSR) is not a factor")
}

# Remove NA from the analysis ------------------------------------------

data <- data %>%
tidyr::drop_na(AVAL, CNSR)

if (!is.null(strata)){
data <- data %>%
tidyr::drop_na(any_of({{strata}}))
}

# Ensure the presence of at least one strata ---------------------------
strata <- ifelse(is.null(strata), 1, strata %>% paste(collapse = " + "))

# cuminc ---------------------------------------------------------------
cuminc <-
tidycmprsk::cuminc(
formula = stats::as.formula(paste0("survival::Surv(", AVAL, ", ", CNSR, ") ~ ", strata)),
Expand Down
5 changes: 2 additions & 3 deletions R/utils_visr.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
#'
#' @return List of \code{ggplot} with equal width.
#'
#' @references \url{https://stackoverflow.com/questions/26159495/align-multiple-ggplot-
#' graphs-with-and-without-legends}
#' @references \url{https://stackoverflow.com/questions/26159495}
#'
#' @examples
#' \donttest{
#'
#' ## create 2 graphs
#' p1 <- ggplot2::ggplot(adtte, ggplot2::aes(x = as.numeric(AGE), fill = "Age")) +
#' ggplot2::geom_histogram(bins = 15)
#'
#'
#' p2 <- ggplot2::ggplot(adtte, ggplot2::aes(x = as.numeric(AGE))) +
#' ggplot2::geom_histogram(bins = 15)
#'
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ coverage](https://codecov.io/gh/openpharma/visR/branch/develop/graph/badge.svg)]
[![pkgdown](https://github.com/openpharma/visR/actions/workflows/makedocs.yml/badge.svg)](https://github.com/openpharma/visR/actions/workflows/makedocs.yml)
[![CRAN
status](https://www.r-pkg.org/badges/version/visR)](https://CRAN.R-project.org/package=visR)
<a href=https://github.com/pharmaR/riskmetric><img src=https://img.shields.io/badge/riskmetric-0.53-green></img></a>
<a href=https://github.com/pharmaR/riskmetric><img src=https://img.shields.io/badge/riskmetric-0.52-green></img></a>
<!-- badges: end -->

## Installation
Expand Down Expand Up @@ -109,11 +109,13 @@ Please note that the `visR` project is released with a [Contributor Code
of Conduct](CODE_OF_CONDUCT.md). By contributing to this project, you
agree to abide by its terms. Thank you to all contributors:

[@AlexandraP-21](https://github.com/AlexandraP-21),
[@ardeeshany](https://github.com/ardeeshany),
[@bailliem](https://github.com/bailliem),
[@ddsjoberg](https://github.com/ddsjoberg),
[@epijim](https://github.com/epijim),
[@gdario](https://github.com/gdario),
[@joanacmbarros](https://github.com/joanacmbarros),
[@lcomm](https://github.com/lcomm),
[@prabhushanmup](https://github.com/prabhushanmup),
[@rebecca-albrecht](https://github.com/rebecca-albrecht),
Expand Down
2 changes: 2 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ authors:
href: "https://www.linkedin.com/in/stevenhaesendonckx/"
James Black:
href: "https://www.epijim.uk/"
Daniel D. Sjoberg:
href: "https://www.danieldsjoberg.com/"

development:
mode: auto
Expand Down
5 changes: 2 additions & 3 deletions man/align_plots.Rd

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

26 changes: 15 additions & 11 deletions man/estimate_cuminc.Rd

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

146 changes: 0 additions & 146 deletions tests/testthat/test-estimate_CUMINC.R

This file was deleted.

Loading

0 comments on commit e0a87f4

Please sign in to comment.