Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review of Joanna testing #361

Merged
merged 10 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
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
63 changes: 49 additions & 14 deletions R/estimate_cuminc.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,64 @@
#' @export
#'
#' @examples
#' estimate_cuminc(
#' tidycmprsk::trial,
#' strata = "trt",
#' CNSR = "death_cr",
#' AVAL = "ttdeath"
#' ) %>%
SHAESEN2 marked this conversation as resolved.
Show resolved Hide resolved
#' 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 %>%
SHAESEN2 marked this conversation as resolved.
Show resolved Hide resolved
#' 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
SHAESEN2 marked this conversation as resolved.
Show resolved Hide resolved
,...) {
# 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."))

# 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
3 changes: 2 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 @@ -114,6 +114,7 @@ agree to abide by its terms. Thank you to all contributors:
[@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.

24 changes: 14 additions & 10 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