From fe838e37d4b0c432531db29ce1b8d27ff09a5e40 Mon Sep 17 00:00:00 2001 From: Dominic Muston Date: Fri, 5 Jan 2024 22:13:24 -0500 Subject: [PATCH] News, and timevar not timepoint --- NEWS.md | 9 ++++++--- R/ppdpps.R | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4e72a45..c9a9f3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,7 @@ -# psm3mkv 0.1.0 +## 5 Jan 2024 - Constraints implied by a PSM -## Version 0.1 -* Initial release +I’ve merged some experimental functions into the main branch following the version 0.1 release package. These functions provide analyses of the constraints on mortality hazards and therefore survival implied by a PSM. They are: [calc_haz_psm()], [calc_surv_psmpps()], [pickout_psmhaz()], [graph_psm_hazards()], and [graph_psm_survs()]. + +# 1 Jan 2024 - Version 0.1 + +This is the initial release of the package, rather belatedly. The code dates to October 2023. diff --git a/R/ppdpps.R b/R/ppdpps.R index edec91c..16058c7 100644 --- a/R/ppdpps.R +++ b/R/ppdpps.R @@ -163,9 +163,9 @@ calc_surv_psmpps <- function(totime, fromtime=0, ptdata, dpam, type="simple") { #' Graph is a line graphic of the hazards plotted against the time-range #' @importFrom rlang .data #' @return adj is the hazard adjusted for constraints, unadj is the unadjusted hazard -pickout_psmhaz <- function(timepoint, endpoint, ptdata, dpam, psmtype) { +pickout_psmhaz <- function(timevar, endpoint, ptdata, dpam, psmtype) { # Run calculation of all hazards - allhaz <- calc_haz_psm(timepoint, ptdata, dpam, psmtype) + allhaz <- calc_haz_psm(timevar, ptdata, dpam, psmtype) # Required hazard, unadjusted h_unadj <- dplyr::case_when( endpoint=="TTP" ~ allhaz$unadj$ttp, @@ -216,14 +216,14 @@ pickout_psmhaz <- function(timepoint, endpoint, ptdata, dpam, psmtype) { #' # dpam=params, #' # psmtype="simple") #' # psmh_simple$graph -graph_psm_hazards <- function(timerange, endpoint, ptdata, dpam, psmtype) { +graph_psm_hazards <- function(timevar, endpoint, ptdata, dpam, psmtype) { # Convert endpoint to upper case text endpoint <- toupper(endpoint) # Pull out hazards to plot (inefficiently calls function twice, but is quite quick) - adjhaz <- timerange |> purrr::map_vec(~pickout_psmhaz(.x, endpoint, ptdata, dpam, psmtype)$adj) - unadjhaz <- timerange |> purrr::map_vec(~pickout_psmhaz(.x, endpoint, ptdata, dpam, psmtype)$unadj) + adjhaz <- timevar |> purrr::map_vec(~pickout_psmhaz(.x, endpoint, ptdata, dpam, psmtype)$adj) + unadjhaz <- timevar |> purrr::map_vec(~pickout_psmhaz(.x, endpoint, ptdata, dpam, psmtype)$unadj) # Create dataset for graphic - result_data <- dplyr::tibble(Time=timerange, Adjusted=adjhaz, Unadjusted=unadjhaz) |> + result_data <- dplyr::tibble(Time=timevar, Adjusted=adjhaz, Unadjusted=unadjhaz) |> tidyr::pivot_longer(cols=c(Adjusted, Unadjusted), names_to="Method", values_to="Hazard") # Draw graphic @@ -264,7 +264,7 @@ graph_psm_hazards <- function(timerange, endpoint, ptdata, dpam, psmtype) { #' # dpam=params, #' # psmtype="simple") #' # psms_simple$graph -graph_psm_survs <- function(timerange, endpoint, ptdata, dpam, psmtype) { +graph_psm_survs <- function(timevar, endpoint, ptdata, dpam, psmtype) { # Convert endpoint to upper case text endpoint <- toupper(endpoint) # Unadjusted hazard @@ -286,13 +286,13 @@ graph_psm_survs <- function(timerange, endpoint, ptdata, dpam, psmtype) { if (intA$message=="OK") intA$value else NA } # Calculate cumulative hazards - cumH_unadj <- seq(timerange) |> purrr::map_dbl(~cumhaz_unadj(.x)) - cumH_adj <- seq(timerange) |> purrr::map_dbl(~cumhaz_adj(.x)) + cumH_unadj <- seq(timevar) |> purrr::map_dbl(~cumhaz_unadj(.x)) + cumH_adj <- seq(timevar) |> purrr::map_dbl(~cumhaz_adj(.x)) # Calculate survival values S_unadj <- exp(-cumH_unadj) S_adj <- exp(-cumH_adj) # Create dataset for graphic - result_data <- dplyr::tibble(Time=timerange, Adjusted=S_adj, Unadjusted=S_unadj) |> + result_data <- dplyr::tibble(Time=timevar, Adjusted=S_adj, Unadjusted=S_unadj) |> tidyr::pivot_longer(cols=c(Adjusted, Unadjusted), names_to="Method", values_to="Survival") # Draw graphic