From de31f6c2aa06fb51509d6e564f36c6018d5f1af0 Mon Sep 17 00:00:00 2001 From: Dominic Muston Date: Mon, 22 Apr 2024 16:28:13 -0400 Subject: [PATCH 1/5] Remove documentation for non-exported functions --- R/basics.R | 16 +++++++-- R/datasets.R | 2 ++ R/discrmd.R | 3 ++ R/fitting-spl.R | 1 + R/fitting.R | 3 ++ R/lhoods.R | 38 +++++++++++++++----- R/ltablesurv.R | 14 +++++--- R/ppdpps.R | 24 +++++++------ R/resmeans.R | 12 +++++++ man/calc_dens.Rd | 34 ------------------ man/calc_dens_par.Rd | 32 ----------------- man/calc_ex.Rd | 28 --------------- man/calc_haz.Rd | 34 ------------------ man/calc_haz_par.Rd | 32 ----------------- man/calc_likes.Rd | 14 ++++---- man/calc_likes_psm_complex.Rd | 53 ---------------------------- man/calc_likes_psm_simple.Rd | 53 ---------------------------- man/calc_likes_stm_cf.Rd | 53 ---------------------------- man/calc_likes_stm_cr.Rd | 53 ---------------------------- man/calc_ltdens.Rd | 21 ----------- man/calc_ltsurv.Rd | 21 ----------- man/calc_pdist.Rd | 37 -------------------- man/calc_pdist_par.Rd | 32 ----------------- man/calc_rmd.Rd | 4 +-- man/calc_rmd_first.Rd | 27 -------------- man/calc_rmd_par.Rd | 32 ----------------- man/calc_surv.Rd | 37 -------------------- man/check_posdef.Rd | 17 --------- man/convert_fit2spec.Rd | 25 ------------- man/convert_wks2yrs.Rd | 20 ----------- man/convert_yrs2wks.Rd | 20 ----------- man/create_dummydata_flexbosms.Rd | 17 --------- man/create_dummydata_survcan.Rd | 17 --------- man/drmd_psm.Rd | 58 ------------------------------- man/drmd_stm_cf.Rd | 35 ------------------- man/drmd_stm_cr.Rd | 35 ------------------- man/fit_ends_mods_given.Rd | 30 ---------------- man/fit_mods.Rd | 29 ---------------- man/fit_mods_par.Rd | 29 ---------------- man/fit_mods_spl.Rd | 41 ---------------------- man/give_noparams.Rd | 35 ------------------- man/give_noparams_par.Rd | 20 ----------- man/graph_psm_hazards.Rd | 22 +++++++----- man/graph_psm_survs.Rd | 8 +++-- man/pickout_psmhaz.Rd | 31 ----------------- man/prmd_os_psm.Rd | 17 --------- man/prmd_pd_stm_cf.Rd | 17 --------- man/prmd_pd_stm_cr.Rd | 17 --------- man/prmd_pf_psm.Rd | 17 --------- man/prmd_pf_stm.Rd | 17 --------- man/rmd_os_psm.Rd | 26 -------------- man/rmd_pd_stm_cf.Rd | 26 -------------- man/rmd_pd_stm_cr.Rd | 28 --------------- man/rmd_pf_psm.Rd | 26 -------------- man/rmd_pf_stm.Rd | 26 -------------- man/vonelookup.Rd | 32 ----------------- 56 files changed, 116 insertions(+), 1332 deletions(-) delete mode 100644 man/calc_dens.Rd delete mode 100644 man/calc_dens_par.Rd delete mode 100644 man/calc_ex.Rd delete mode 100644 man/calc_haz.Rd delete mode 100644 man/calc_haz_par.Rd delete mode 100644 man/calc_likes_psm_complex.Rd delete mode 100644 man/calc_likes_psm_simple.Rd delete mode 100644 man/calc_likes_stm_cf.Rd delete mode 100644 man/calc_likes_stm_cr.Rd delete mode 100644 man/calc_ltdens.Rd delete mode 100644 man/calc_ltsurv.Rd delete mode 100644 man/calc_pdist.Rd delete mode 100644 man/calc_pdist_par.Rd delete mode 100644 man/calc_rmd_first.Rd delete mode 100644 man/calc_rmd_par.Rd delete mode 100644 man/calc_surv.Rd delete mode 100644 man/check_posdef.Rd delete mode 100644 man/convert_fit2spec.Rd delete mode 100644 man/convert_wks2yrs.Rd delete mode 100644 man/convert_yrs2wks.Rd delete mode 100644 man/create_dummydata_flexbosms.Rd delete mode 100644 man/create_dummydata_survcan.Rd delete mode 100644 man/drmd_psm.Rd delete mode 100644 man/drmd_stm_cf.Rd delete mode 100644 man/drmd_stm_cr.Rd delete mode 100644 man/fit_ends_mods_given.Rd delete mode 100644 man/fit_mods.Rd delete mode 100644 man/fit_mods_par.Rd delete mode 100644 man/fit_mods_spl.Rd delete mode 100644 man/give_noparams.Rd delete mode 100644 man/give_noparams_par.Rd delete mode 100644 man/pickout_psmhaz.Rd delete mode 100644 man/prmd_os_psm.Rd delete mode 100644 man/prmd_pd_stm_cf.Rd delete mode 100644 man/prmd_pd_stm_cr.Rd delete mode 100644 man/prmd_pf_psm.Rd delete mode 100644 man/prmd_pf_stm.Rd delete mode 100644 man/rmd_os_psm.Rd delete mode 100644 man/rmd_pd_stm_cf.Rd delete mode 100644 man/rmd_pd_stm_cr.Rd delete mode 100644 man/rmd_pf_psm.Rd delete mode 100644 man/rmd_pf_stm.Rd delete mode 100644 man/vonelookup.Rd diff --git a/R/basics.R b/R/basics.R index 9209113..2cc43a5 100644 --- a/R/basics.R +++ b/R/basics.R @@ -35,6 +35,7 @@ #' - Generalized Gamma requires the mu, sigma and Q parameters if using the standard parameterization (`gengamma`) or shape, scale and k parameters if using the original parameterization (`gengamma.orig`). #' @seealso [flexsurv::flexsurvreg] #' @return The value of the distribution function, a numeric value. +#' @noRd # Examples # calc_pdist_par(10, "exp", 0.01) # calc_pdist_par(5, "lnorm", c(3, 1)) @@ -80,6 +81,7 @@ calc_pdist_par <- function(time, dist, pars) { #' - `scale` - Either "hazard", "odds", or "normal", as described in [flexsurv::flexsurvspline]. With the default of no knots in addition to the boundaries, this model reduces to the Weibull, log-logistic and log-normal respectively. The scale must be common to all times. #' @seealso [flexsurv::flexsurvspline] and [flexsurv::flexsurvreg] #' @return The value of the distribution function, a numeric value. +#' @noRd # Examples # calc_pdist(time=1:5, # type="spl", @@ -114,6 +116,7 @@ calc_pdist <- function(time, type, spec){ #' @inheritParams calc_pdist #' @return The value of the survival function, a numeric value. #' @inherit calc_pdist seealso +#' @noRd # Examples # calc_surv(time=1:5, # type="spl", @@ -132,6 +135,7 @@ calc_surv <- function(time, type, spec) { #' @inheritParams calc_pdist_par #' @inherit calc_pdist_par seealso #' @return The value of a hazard function, a numeric value. +#' @noRd # Examples # calc_haz_par(10, "exp", 0.01) # calc_haz_par(5, "lnorm", c(3, 1)) @@ -163,6 +167,7 @@ calc_haz_par <- function(time, dist, pars) { #' @description Calculate the value of the hazard function, given specification as either parametric or Royston-Parmar splines model #' @inheritParams calc_surv #' @inherit calc_haz_par return +#' @noRd # Examples # calc_haz(time=1:5, # type="spl", @@ -195,6 +200,7 @@ calc_haz <- function(time, type, spec){ #' @inheritParams calc_pdist_par #' @inherit calc_pdist_par seealso #' @return The value of a density function, a numeric value. +#' @noRd # Examples # calc_dens_par(10, "exp", 0.01) # calc_dens_par(5, "lnorm", c(3, 1)) @@ -226,6 +232,7 @@ calc_dens_par <- function(time, dist, pars) { #' @description Calculate the value of the density function, given specification as either parametric or Royston-Parmar splines model #' @inheritParams calc_surv #' @inherit calc_haz_par return +#' @noRd # Examples # calc_dens(time=1:5, # type="spl", @@ -266,6 +273,7 @@ calc_dens <- function(time, type, spec){ #' @param Tw is the time period over which the restricted mean is calculated #' @inherit calc_pdist seealso #' @return the restricted mean duration, a numeric value. +#' @noRd # Examples # calc_rmd_par(20, "exp", 0.2) # calc_rmd_par(10, "lnorm", c(3, 1)) @@ -310,8 +318,8 @@ calc_rmd_par <- function(Tw, dist, pars) { #' - `knots` - Vector of locations of knots on the axis of log time, supplied in increasing order. Unlike in [flexsurv::flexsurvspline], these include the two boundary knots. #' - `scale` - Either "hazard", "odds", or "normal", as described in [flexsurv::flexsurvspline]. With the default of no knots in addition to the boundaries, this model reduces to the Weibull, log-logistic and log-normal respectively. The scale must be common to all times. #' @param discrate Discounting rate (%) per year -#' @inherit calc_haz_par seealso -#' @inherit calc_haz_par return +#' @returns Numeric +#' @seealso [flexsurv::flexsurvspline] and [flexsurv::flexsurvreg] #' @export #' @examples #' calc_rmd(Tw=200, @@ -347,6 +355,7 @@ calc_rmd <- function(Tw, type, spec, discrate=0){ #' @param dist is the statistical distribution (named per [flexsurv::flexsurvreg]) #' @return a numeric value #' @inherit calc_pdist seealso +#' @noRd # Examples # give_noparams_par("llogis") give_noparams_par <- function(dist) { @@ -365,6 +374,7 @@ give_noparams_par <- function(dist) { #' @inheritParams calc_surv #' @return a numeric value #' @inherit calc_pdist seealso +#' @noRd # Examples # give_noparams(type="par", spec=list(dist="weibullPH")) # give_noparams(type="spl", spec=list(gamma=c(1.1,2.1,3.1))) @@ -386,6 +396,7 @@ give_noparams <- function(type, spec) { #' @param weeks Number of weeks #' @return Number of years = weeks x 7 / 365.25 #' @seealso [psm3mkv::convert_yrs2wks] +#' @noRd convert_wks2yrs <- function(weeks) { weeks*7/365.25 } @@ -395,6 +406,7 @@ convert_wks2yrs <- function(weeks) { #' @param years Number of years #' @return Number of weeks = years / 7 * 365.25 #' @seealso [psm3mkv::convert_wks2yrs] +#' @noRd convert_yrs2wks <- function(years) { years*365.25/7 } \ No newline at end of file diff --git a/R/datasets.R b/R/datasets.R index 8354b82..91cf582 100644 --- a/R/datasets.R +++ b/R/datasets.R @@ -46,6 +46,7 @@ create_dummydata <- function(dsname) { #' @return Tibble dataset, for use with [psm3mkv] functions #' @seealso [create_dummydata()] #' @importFrom rlang .data +#' @noRd create_dummydata_survcan <- function() { # Declare local variables ptid <- os.durn <- os.flag <- NULL @@ -64,6 +65,7 @@ create_dummydata_survcan <- function() { #' @return Tibble dataset, for use with [psm3mkv] functions #' @seealso [create_dummydata()] #' @importFrom rlang .data +#' @noRd create_dummydata_flexbosms <- function() { # Declare local variables id <- pfs.durn <- pfs.flag <- NULL diff --git a/R/discrmd.R b/R/discrmd.R index ddaedc4..a573dd3 100644 --- a/R/discrmd.R +++ b/R/discrmd.R @@ -45,6 +45,7 @@ #' - pd: RMD in PD state #' - os: RMD in either alive state #' @seealso [drmd_stm_cf()] [drmd_stm_cr()] +#' @noRd # Examples # # Create dataset and fit survival models (splines) # bosonc <- create_dummydata("flexbosms") @@ -93,6 +94,7 @@ drmd_psm <- function(ptdata, dpam, psmtype="simple", Ty=10, discrate=0, lifetabl #' Calculate restricted mean duration (RMD) in PF, PD and OS states under a State Transition Model Clock Forward structure. #' @inherit drmd_psm params return #' @seealso [drmd_psm()] [drmd_stm_cr()] +#' @noRd # Examples # # Create dataset and fit survival models (splines) # bosonc <- create_dummydata("flexbosms") @@ -149,6 +151,7 @@ drmd_stm_cf <- function(dpam, Ty=10, discrate=0, lifetable=NA, timestep=1) { #' Calculate restricted mean duration (RMD) in PF, PD and OS states under a State Transition Model Clock Reset structure. #' @inherit drmd_psm params return #' @seealso [drmd_stm_cf()] [drmd_psm()] +#' @noRd # Examples # # Create dataset and fit survival models (splines) # bosonc <- create_dummydata("flexbosms") diff --git a/R/fitting-spl.R b/R/fitting-spl.R index 17ff198..baa60c8 100644 --- a/R/fitting-spl.R +++ b/R/fitting-spl.R @@ -33,6 +33,7 @@ #' - result: A list of class [flexsurv::flexsurvspline] containing information about the fitted model. #' - error: Any error message returned on fitting the regression (NULL indicates no error). #' @seealso [flexsurv::flexsurvspline] and [survival::Surv()] +#' @noRd fit_mods_spl <- function(durn1, durn2=NA, evflag, knot_set=1:3, scale_set=c("hazard", "odds", "normal"), diff --git a/R/fitting.R b/R/fitting.R index 763fca1..7ac3751 100644 --- a/R/fitting.R +++ b/R/fitting.R @@ -25,6 +25,7 @@ #' @description Checks whether the Hessian matrix returned in a list after fitting a survival regression with flexsurvreg is positive-definite. #' @param fitlist is a list returned after running [flexsurv::flexsurvreg()] describing a fitted survival model #' @return logical: TRUE if Hessian matrix is positive definite, FALSE if not. +#' @noRd # Examples # bosonc <- create_dummydata("flexbosms") # fits <- fit_ends_mods_par(bosonc) @@ -56,6 +57,7 @@ check_posdef <- function(fitlist) { #' @return A list by distribution, each containing two components: #' - result: A list of class [flexsurv::flexsurvreg] containing information about the fitted model. #' - error: Any error message returned on fitting the regression (NULL indicates no error). +#' @noRd fit_mods_par <- function(durn1, durn2=NA, evflag, dists, expvar=NA) { # Return nothing if no distributions specified if (sum(is.na(dists))!=0) {return(NA)} @@ -90,6 +92,7 @@ fit_mods_par <- function(durn1, durn2=NA, evflag, dists, expvar=NA) { #' @return A list by distribution, each containing two components: #' - result: A list containing information about the fitted model. #' - error: Any error message returned on fitting the regression (NULL indicates no error). +#' @noRd fit_mods <- function(durn1, durn2=NA, evflag, type, spec) { if (type=="spl"){ fit_mods_spl(durn1, durn2, evflag, knot_set=spec$k, scale_set=spec$scale) diff --git a/R/lhoods.R b/R/lhoods.R index 101caa7..af4b0c9 100644 --- a/R/lhoods.R +++ b/R/lhoods.R @@ -28,6 +28,7 @@ #' - `spec` contains distribution (`dist`) and coefficients (`coefs`) if `type=="par"` #' - `spec` contains gamma values (`gamma`), knot locations (log scale, `knots`) and scale (`scale`) for Royston-Parmar splines model, if `type=="spl"` #' @seealso [flexsurv::flexsurvspline()] +#' @noRd # Examples # bosonc <- create_dummydata("flexbosms") # fits <- fit_ends_mods_spl(bosonc) @@ -53,13 +54,13 @@ convert_fit2spec <- function(fitsurv) { #' Calculate likelihood for a simple three-state partitioned survival model #' @description Calculate likelihood values and other summary output for a simple three-state partitioned survival model, given appropriately formatted patient-level data, a set of fitted survival regressions, and the time cut-off (if two-piece modeling is used). This function is called by [calc_likes].x three-state partitioned survival model, given appropriately formatted patient-level data, a set of fitted survival regressions, and the time cut-off (if two-piece modeling is used). This function is called by [calc_likes]. Unlike [calc_likes_psm_complex], this likelihood function assumes a progression hazard can be derived from the PFS hazard function and the ratio of progression to PFS events from PF patients. #' @param ptdata Dataset of patient level data. Must be a tibble with columns named: -#' - ptid: patient identifier -#' - pfs.durn: duration of PFS from baseline -#' - pfs.flag: event flag for PFS (=1 if progression or death occurred, 0 for censoring) -#' - os.durn: duration of OS from baseline -#' - os.flag: event flag for OS (=1 if death occurred, 0 for censoring) -#' - ttp.durn: duration of TTP from baseline (usually should be equal to pfs.durn) -#' - ttp.flag: event flag for TTP (=1 if progression occurred, 0 for censoring). +#' - `ptid`: patient identifier +#' - `pfs.durn`: duration of PFS from baseline +#' - `pfs.flag`: event flag for PFS (=1 if progression or death occurred, 0 for censoring) +#' - `os.durn`: duration of OS from baseline +#' - `os.flag`: event flag for OS (=1 if death occurred, 0 for censoring) +#' - `ttp.durn`: duration of TTP from baseline (usually should be equal to pfs.durn) +#' - `ttp.flag`: event flag for TTP (=1 if progression occurred, 0 for censoring). #' #' Survival data for all other endpoints (time to progression, pre-progression death, post-progression survival) are derived from PFS and OS. #' @param dpam List of survival regressions for each endpoint: @@ -81,6 +82,7 @@ convert_fit2spec <- function(fitsurv) { #' - `BIC`: Bayesian Information Criterion value for this model #' @seealso [calc_likes()], [calc_likes_psm_complex()], [calc_likes_stm_cf()], [calc_likes_stm_cr()] #' @importFrom rlang .data +#' @noRd # Examples # bosonc <- create_dummydata("flexbosms") # fits <- fit_ends_mods_spl(bosonc) @@ -181,6 +183,7 @@ calc_likes_psm_simple <- function(ptdata, dpam, cuttime=0) { #' @inherit calc_likes_psm_simple return #' @seealso [calc_likes()], [calc_likes_psm_simple()], [calc_likes_psm_complex()], [calc_likes_stm_cr()] #' @importFrom rlang .data +#' @noRd # Examples # bosonc <- create_dummydata("flexbosms") # fits <- fit_ends_mods_par(bosonc) @@ -285,6 +288,7 @@ calc_likes_psm_complex <- function(ptdata, dpam, cuttime=0) { #' @inherit calc_likes_psm_simple return #' @seealso [calc_likes()], [calc_likes_psm_simple()], [calc_likes_psm_complex()], [calc_likes_stm_cr()] #' @importFrom rlang .data +#' @noRd # Examples # bosonc <- create_dummydata("flexbosms") # fits <- fit_ends_mods_spl(bosonc) @@ -377,6 +381,7 @@ calc_likes_stm_cf <- function(ptdata, dpam, cuttime=0) { #' @inherit calc_likes_psm_simple return #' @seealso [calc_likes()], [calc_likes_stm_cf()], [calc_likes_psm_simple()], [calc_likes_psm_complex()] #' @importFrom rlang .data +#' @noRd # Examples # bosonc <- create_dummydata("flexbosms") # fits <- fit_ends_mods_spl(bosonc) @@ -466,7 +471,24 @@ calc_likes_stm_cr <- function(ptdata, dpam, cuttime=0) { #' Calculate likelihoods for three three-state model structures #' @description Calculate likelihood values and other summary output for the following three state models structures: partitioned survival, clock forward state transition, and clock reset state transition. The function requires appropriately formatted patient-level data, a set of fitted survival regressions, and the time cut-off (if two-piece modeling is used). -#' @inheritParams calc_likes_psm_simple +#' @param ptdata Dataset of patient level data. Must be a tibble with columns named: +#' - `ptid`: patient identifier +#' - `pfs.durn`: duration of PFS from baseline +#' - `pfs.flag`: event flag for PFS (=1 if progression or death occurred, 0 for censoring) +#' - `os.durn`: duration of OS from baseline +#' - `os.flag`: event flag for OS (=1 if death occurred, 0 for censoring) +#' - `ttp.durn`: duration of TTP from baseline (usually should be equal to pfs.durn) +#' - `ttp.flag`: event flag for TTP (=1 if progression occurred, 0 for censoring). +#' +#' Survival data for all other endpoints (time to progression, pre-progression death, post-progression survival) are derived from PFS and OS. +#' @param dpam List of survival regressions for each endpoint: +#' - pre-progression death (PPD) +#' - time to progression (TTP) +#' - progression-free survival (PFS) +#' - overall survival (OS) +#' - post-progression survival clock forward (PPS-CF) and +#' - post-progression survival clock reset (PPS-CR). +#' @param cuttime Time cutoff - this is nonzero for two-piece models. #' @return Two outputs are returned: #' #' `results` is a tibble of values and data relating to the likelihood for this model: diff --git a/R/ltablesurv.R b/R/ltablesurv.R index 7c6a3fc..7a47627 100644 --- a/R/ltablesurv.R +++ b/R/ltablesurv.R @@ -33,6 +33,7 @@ #' - `arith`: Arithmetic mean, where interpolation is required between measured values #' - `geom`: Geometric mean, where interpolation is required between measured values #' @seealso [psm3mkv::vlookup] +#' @noRd vonelookup <- function(oneindexval, indexvec, valvec, method="geom") { if (is.na(oneindexval)) return(NA) # Return NA rather than error if index value lookup is NA if (oneindexval Date: Mon, 22 Apr 2024 17:12:42 -0400 Subject: [PATCH 2/5] Fix seealso cross-references --- R/lhoods.R | 1 - R/resmeans.R | 1 - man/calc_allrmds.Rd | 3 --- man/calc_likes.Rd | 3 --- 4 files changed, 8 deletions(-) diff --git a/R/lhoods.R b/R/lhoods.R index af4b0c9..9d91eab 100644 --- a/R/lhoods.R +++ b/R/lhoods.R @@ -509,7 +509,6 @@ calc_likes_stm_cr <- function(ptdata, dpam, cuttime=0) { #' #' The number of patients for each outcome are given for each model structure. You may confirm that these are identical across model structures. #' The contribution of each patient group to the calculation of log-likelihood for each model is given in fields beginning `ll_`. This is helpful for understanding differences in likelihoods between model structures, according to patient outcomes. -#' @seealso This function calls [calc_likes_psm_simple()], [calc_likes_psm_complex()], [calc_likes_stm_cf()], and [calc_likes_stm_cr()]. #' @export #' @examples #' \donttest{ diff --git a/R/resmeans.R b/R/resmeans.R index 21f6dff..418c045 100644 --- a/R/resmeans.R +++ b/R/resmeans.R @@ -448,7 +448,6 @@ calc_rmd_first <- function(ds, cuttime) { #' @return List of detailed numeric results #' - cutadj indicates the survival function and area under the curves for PFS and OS up to the cutpoint #' - results provides results of the restricted means calculations, by model and state. -#' @seealso Restricted means are provided by [rmd_pf_psm()], [rmd_os_psm()], [rmd_pf_stm()], [rmd_pd_stm_cf()] and [rmd_pd_stm_cr()]. The function [calc_allrmds_boot] provides a version for bootstrapping. #' @export #' @examples #' \donttest{ diff --git a/man/calc_allrmds.Rd b/man/calc_allrmds.Rd index 4840165..bb4865f 100644 --- a/man/calc_allrmds.Rd +++ b/man/calc_allrmds.Rd @@ -77,6 +77,3 @@ calc_allrmds(bosonc, dpam=params) calc_allrmds(bosonc, dpam=params, rmdmethod="disc", timestep=1) } } -\seealso{ -Restricted means are provided by \code{\link[=rmd_pf_psm]{rmd_pf_psm()}}, \code{\link[=rmd_os_psm]{rmd_os_psm()}}, \code{\link[=rmd_pf_stm]{rmd_pf_stm()}}, \code{\link[=rmd_pd_stm_cf]{rmd_pd_stm_cf()}} and \code{\link[=rmd_pd_stm_cr]{rmd_pd_stm_cr()}}. The function \link{calc_allrmds_boot} provides a version for bootstrapping. -} diff --git a/man/calc_likes.Rd b/man/calc_likes.Rd index 55bd64d..992a0cb 100644 --- a/man/calc_likes.Rd +++ b/man/calc_likes.Rd @@ -77,6 +77,3 @@ params <- list( calc_likes(bosonc, dpam=params) } } -\seealso{ -This function calls \code{\link[=calc_likes_psm_simple]{calc_likes_psm_simple()}}, \code{\link[=calc_likes_psm_complex]{calc_likes_psm_complex()}}, \code{\link[=calc_likes_stm_cf]{calc_likes_stm_cf()}}, and \code{\link[=calc_likes_stm_cr]{calc_likes_stm_cr()}}. -} From 2909a24992cd17b7775f13771e66c633afaa7c0e Mon Sep 17 00:00:00 2001 From: Dominic Muston Date: Mon, 22 Apr 2024 17:41:10 -0400 Subject: [PATCH 3/5] Don't test graph_psm_hazards --- R/ppdpps.R | 17 ++++++++++------- vignettes/psm3mkv.bib | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/R/ppdpps.R b/R/ppdpps.R index 8ff9978..9aee456 100644 --- a/R/ppdpps.R +++ b/R/ppdpps.R @@ -269,6 +269,7 @@ graph_psm_hazards <- function(timevar, endpoint, ptdata, dpam, psmtype) { #' @importFrom rlang .data #' @export #' @examples +#' \donttest{ #' bosonc <- create_dummydata("flexbosms") #' fits <- fit_ends_mods_par(bosonc) #' # Pick out best distribution according to min AIC @@ -284,13 +285,15 @@ graph_psm_hazards <- function(timevar, endpoint, ptdata, dpam, psmtype) { #' graph_orig <- graph_survs(ptdata=bosonc, dpam=params) #' graph_orig$graph$os #' # New graphic illustrating effect of constraints on OS model -#' # psms_simple <- graph_psm_survs( -#' # timerange=6*(0:10), -#' # endpoint="OS", -#' # ptdata=bosonc, -#' # dpam=params, -#' # psmtype="simple") -#' # psms_simple$graph +#' psms_simple <- graph_psm_survs( +#' timerange=6*(0:10), +#' endpoint="OS", +#' ptdata=bosonc, +#' dpam=params, +#' psmtype="simple" +#' ) +#' psms_simple$graph +#' } graph_psm_survs <- function(timevar, endpoint, dpam, psmtype) { # Declare local variables Adjusted <- Unadjusted <- Time <- Survival <- Method <- NULL diff --git a/vignettes/psm3mkv.bib b/vignettes/psm3mkv.bib index 21c57b3..05e689a 100644 --- a/vignettes/psm3mkv.bib +++ b/vignettes/psm3mkv.bib @@ -104,14 +104,14 @@ @Manual{pack_tibble url = {https://CRAN.R-project.org/package=tibble}, } -@Manual{@pack_boot, +@Manual{pack_boot, title = {boot: Bootstrap R (S-Plus) Functions}, author = {{Angelo Canty} and {B. D. Ripley}}, year = {2024}, note = {R package version 1.3-29}, } -@Manual{@pack_ggsci, +@Manual{pack_ggsci, title = {ggsci: Scientific Journal and Sci-Fi Themed Color Palettes for 'ggplot2'}, author = {Nan Xiao}, From df59028f4bf45deb1525f88d4309193af71cb060 Mon Sep 17 00:00:00 2001 From: Dominic Muston Date: Mon, 22 Apr 2024 18:02:52 -0400 Subject: [PATCH 4/5] Remove ptdata dependency in graph_psms --- R/ppdpps.R | 11 +++-------- man/graph_psm_survs.Rd | 17 ++++++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/R/ppdpps.R b/R/ppdpps.R index 9aee456..5d9d4e8 100644 --- a/R/ppdpps.R +++ b/R/ppdpps.R @@ -239,11 +239,10 @@ pickout_psmhaz <- function(timevar, endpoint=NA, dpam, psmtype) { #' # psmh_simple <- graph_psm_hazards( #' # timerange=(0:10)*6, #' # endpoint="OS", -#' # ptdata=bosonc, #' # dpam=params, #' # psmtype="simple") #' # psmh_simple$graph -graph_psm_hazards <- function(timevar, endpoint, ptdata, dpam, psmtype) { +graph_psm_hazards <- function(timevar, endpoint, dpam, psmtype) { # Declare local variables Adjusted <- Unadjusted <- Time <- Hazard <- Method <- NULL # Convert endpoint to upper case text @@ -281,14 +280,10 @@ graph_psm_hazards <- function(timevar, endpoint, ptdata, dpam, psmtype) { #' pps_cf = find_bestfit_par(fits$pps_cf, "aic")$fit, #' pps_cr = find_bestfit_par(fits$pps_cr, "aic")$fit #' ) -#' # Original OS graphic -#' graph_orig <- graph_survs(ptdata=bosonc, dpam=params) -#' graph_orig$graph$os -#' # New graphic illustrating effect of constraints on OS model +#' # Graphic illustrating effect of constraints on OS model #' psms_simple <- graph_psm_survs( -#' timerange=6*(0:10), +#' timevar=6*(0:10), #' endpoint="OS", -#' ptdata=bosonc, #' dpam=params, #' psmtype="simple" #' ) diff --git a/man/graph_psm_survs.Rd b/man/graph_psm_survs.Rd index 34c8dc3..88ce302 100644 --- a/man/graph_psm_survs.Rd +++ b/man/graph_psm_survs.Rd @@ -34,6 +34,7 @@ List containing: Graph the PSM survival functions } \examples{ +\donttest{ bosonc <- create_dummydata("flexbosms") fits <- fit_ends_mods_par(bosonc) # Pick out best distribution according to min AIC @@ -49,11 +50,13 @@ params <- list( graph_orig <- graph_survs(ptdata=bosonc, dpam=params) graph_orig$graph$os # New graphic illustrating effect of constraints on OS model -# psms_simple <- graph_psm_survs( -# timerange=6*(0:10), -# endpoint="OS", -# ptdata=bosonc, -# dpam=params, -# psmtype="simple") -# psms_simple$graph +psms_simple <- graph_psm_survs( + timerange=6*(0:10), + endpoint="OS", + ptdata=bosonc, + dpam=params, + psmtype="simple" +) +psms_simple$graph +} } From 6f0560cc899055c5a4a5b7415915ce645d81a59c Mon Sep 17 00:00:00 2001 From: Dominic Muston Date: Mon, 22 Apr 2024 20:06:40 -0400 Subject: [PATCH 5/5] Misc changes to address check() issues --- R/ppdpps.R | 17 +++++++++-------- man/graph_psm_hazards.Rd | 1 - man/graph_psm_survs.Rd | 20 ++++++++++++++------ vignettes/mortality-adjustments.Rmd | 4 +++- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/R/ppdpps.R b/R/ppdpps.R index 5d9d4e8..93b5319 100644 --- a/R/ppdpps.R +++ b/R/ppdpps.R @@ -181,9 +181,9 @@ calc_surv_psmpps <- function(totime, fromtime=0, ptdata, dpam, psmtype="simple") #' @importFrom rlang .data #' @return `adj` is the hazard adjusted for constraints, `unadj` is the unadjusted hazard #' @noRd -pickout_psmhaz <- function(timevar, endpoint=NA, dpam, psmtype) { +pickout_psmhaz <- function(timevar, endpoint=NA, ptdata, dpam, psmtype) { # Run calculation of all hazards - allhaz <- calc_haz_psm(timevar, dpam, psmtype) + allhaz <- calc_haz_psm(timevar, ptdata, dpam, psmtype) # Required hazard, unadjusted h_unadj <- dplyr::case_when( endpoint=="TTP" ~ allhaz$unadj$ttp, @@ -242,14 +242,14 @@ pickout_psmhaz <- function(timevar, endpoint=NA, dpam, psmtype) { #' # dpam=params, #' # psmtype="simple") #' # psmh_simple$graph -graph_psm_hazards <- function(timevar, endpoint, dpam, psmtype) { +graph_psm_hazards <- function(timevar, endpoint, ptdata, dpam, psmtype) { # Declare local variables Adjusted <- Unadjusted <- Time <- Hazard <- Method <- NULL # Convert endpoint to upper case text endpoint <- toupper(endpoint) # Pull out hazards to plot (inefficiently calls function twice, but is quite quick) - adjhaz <- timevar |> purrr::map_vec(~pickout_psmhaz(.x, endpoint, dpam, psmtype)$adj) - unadjhaz <- timevar |> purrr::map_vec(~pickout_psmhaz(.x, endpoint, 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=timevar, Adjusted=adjhaz, Unadjusted=unadjhaz) |> tidyr::pivot_longer(cols=c(Adjusted, Unadjusted), @@ -284,23 +284,24 @@ graph_psm_hazards <- function(timevar, endpoint, dpam, psmtype) { #' psms_simple <- graph_psm_survs( #' timevar=6*(0:10), #' endpoint="OS", +#' ptdata=bosonc, #' dpam=params, #' psmtype="simple" #' ) #' psms_simple$graph #' } -graph_psm_survs <- function(timevar, endpoint, dpam, psmtype) { +graph_psm_survs <- function(timevar, endpoint, ptdata, dpam, psmtype) { # Declare local variables Adjusted <- Unadjusted <- Time <- Survival <- Method <- NULL # Convert endpoint to upper case text endpoint <- toupper(endpoint) # Unadjusted hazard haz_unadj <- function(time) { - pickout_psmhaz(time, endpoint, dpam, psmtype)$unadj + pickout_psmhaz(time, endpoint, ptdata, dpam, psmtype)$unadj } # Adjusted hazard haz_adj <- function(time) { - pickout_psmhaz(time, endpoint, dpam, psmtype)$adj + pickout_psmhaz(time, endpoint, ptdata, dpam, psmtype)$adj } # Unadjusted cumulative hazard cumhaz_unadj <- function(time) { diff --git a/man/graph_psm_hazards.Rd b/man/graph_psm_hazards.Rd index 62ef939..e8fb076 100644 --- a/man/graph_psm_hazards.Rd +++ b/man/graph_psm_hazards.Rd @@ -60,7 +60,6 @@ params <- list( # psmh_simple <- graph_psm_hazards( # timerange=(0:10)*6, # endpoint="OS", -# ptdata=bosonc, # dpam=params, # psmtype="simple") # psmh_simple$graph diff --git a/man/graph_psm_survs.Rd b/man/graph_psm_survs.Rd index 88ce302..9427489 100644 --- a/man/graph_psm_survs.Rd +++ b/man/graph_psm_survs.Rd @@ -4,13 +4,24 @@ \alias{graph_psm_survs} \title{Graph the PSM survival functions} \usage{ -graph_psm_survs(timevar, endpoint, dpam, psmtype) +graph_psm_survs(timevar, endpoint, ptdata, dpam, psmtype) } \arguments{ \item{timevar}{Vector of times at which to calculate the hazards} \item{endpoint}{Endpoint for which hazard is required (TTP, PPD, PFS, OS or PPS)} +\item{ptdata}{Dataset of patient level data. Must be a tibble with columns named: +\itemize{ +\item \code{ptid}: patient identifier +\item \code{pfs.durn}: duration of PFS from baseline +\item \code{pfs.flag}: event flag for PFS (=1 if progression or death occurred, 0 for censoring) +\item \code{os.durn}: duration of OS from baseline +\item \code{os.flag}: event flag for OS (=1 if death occurred, 0 for censoring) +\item \code{ttp.durn}: duration of TTP from baseline (usually should be equal to pfs.durn) +\item \code{ttp.flag}: event flag for TTP (=1 if progression occurred, 0 for censoring). +}} + \item{dpam}{List of survival regressions for each endpoint: \itemize{ \item pre-progression death (PPD) @@ -46,12 +57,9 @@ params <- list( pps_cf = find_bestfit_par(fits$pps_cf, "aic")$fit, pps_cr = find_bestfit_par(fits$pps_cr, "aic")$fit ) -# Original OS graphic -graph_orig <- graph_survs(ptdata=bosonc, dpam=params) -graph_orig$graph$os -# New graphic illustrating effect of constraints on OS model +# Graphic illustrating effect of constraints on OS model psms_simple <- graph_psm_survs( - timerange=6*(0:10), + timevar=6*(0:10), endpoint="OS", ptdata=bosonc, dpam=params, diff --git a/vignettes/mortality-adjustments.Rmd b/vignettes/mortality-adjustments.Rmd index e005885..b26e565 100644 --- a/vignettes/mortality-adjustments.Rmd +++ b/vignettes/mortality-adjustments.Rmd @@ -114,7 +114,6 @@ First we load the packages we need - all of which are suggested for or imported ```{r packages, message=FALSE} library("dplyr") -library("HMDHFDplus") library("psm3mkv") library("tibble") ``` @@ -124,6 +123,9 @@ library("tibble") In order to apply constraints to background mortality, we need some background mortality data, in the form of a lifetable. We can take this from the Human Mortality Database using the *HMDHFDplus* package mentioned above (with thanks to Robert Hettle for the recommendation). The lifetable will need to start from an assumed age at baseline. Lifetables are constructed by time in years. ```{r ltable1, eval=FALSE} +# HMD HFD package +library("HMDHFDplus") + # Assumed population age at baseline (time=0) baseage <- 51.0