Skip to content

Commit ba0ad57

Browse files
authored
Merge pull request #20 from Merck/Nextrel
Aim to address check() issues
2 parents 110535f + a526bc1 commit ba0ad57

11 files changed

+56
-37
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Imports:
2222
flexsurv,
2323
ggplot2,
2424
purrr,
25-
remotes,
2625
rlang,
2726
SimplicialCubature,
2827
stats,
@@ -36,6 +35,7 @@ Suggests:
3635
ggsci,
3736
HMDHFDplus,
3837
knitr,
38+
remotes,
3939
rmarkdown,
4040
testthat (>= 3.0.0)
4141
VignetteBuilder: knitr
@@ -46,6 +46,7 @@ Collate:
4646
'basics.R'
4747
'brier.R'
4848
'datasets.R'
49+
'discrmd.R'
4950
'fitting-spl.R'
5051
'fitting.R'
5152
'lhoods.R'
@@ -54,4 +55,3 @@ Collate:
5455
'probgraphs.R'
5556
'psm3mkv-package.R'
5657
'resmeans.R'
57-
'discrmd.R'

R/discrmd.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ drmd_stm_cf <- function(dpam, Ty=10, discrate=0, lifetable=NA, timestep=1) {
166166
#' pps_cr = find_bestfit_spl(fits$pps_cr, "aic")$fit
167167
#' )
168168
#' drmd_stm_cr(dpam=params)
169-
#' # Add a lifetable constraint
170-
#' ltable <- tibble::tibble(lttime=0:20, lx=1-lttime*0.05)
171-
#' drmd_stm_cr(dpam=params, lifetable=ltable)
169+
#' # Add a lifetable constraint (not run because it's slow)
170+
#' # ltable <- tibble::tibble(lttime=0:20, lx=1-lttime*0.05)
171+
#' # drmd_stm_cr(dpam=params, lifetable=ltable)
172172
drmd_stm_cr <- function(dpam, Ty=10, discrate=0, lifetable=NA, timestep=1) {
173173
# Declare local variables
174174
Tw <- tvec <- ppd.ts <- ttp.ts <- sppd <- sttp <- sos <- NULL

R/lhoods.R

+6-11
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,18 @@
3535
#' convert_fit2spec(fits$pfs[[3]]$result)
3636
convert_fit2spec <- function(fitsurv) {
3737
# Declare local variables
38-
par.dist <- type <- spl.gamma <- spl.knots <- NULL
39-
spl.scale <- spec <- pars <- NULL
38+
par.dist <- type <- spec <- NULL
4039
# Pick out distribution/splines
4140
par.dist <- fitsurv$dlist$name
4241
if (par.dist=="survspline") {
4342
type <- "spl"
44-
spl.gamma <- fitsurv$coefficients
45-
spl.knots <- fitsurv$aux$knots
46-
spl.scale <- fitsurv$aux$scale
47-
spec <- list(gamma=spl.gamma,
48-
knots=spl.knots,
49-
k=length(spl.knots)-2,
50-
scale=spl.scale)
43+
spec <- list(gamma = fitsurv$coefficients,
44+
knots = fitsurv$aux$knots,
45+
k = length(fitsurv$aux$knots)-2,
46+
scale = fitsurv$aux$scale)
5147
} else {
5248
type <- "par"
53-
pars <- fitsurv$res[,1]
54-
spec <- list(dist=par.dist, pars=pars)
49+
spec <- list(dist=par.dist, pars=fitsurv$res[,1])
5550
}
5651
return(list(type=type, spec=spec))
5752
}

R/ppdpps.R

+8
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ pickout_psmhaz <- function(timevar, endpoint=NA, dpam, psmtype) {
204204
#' Graph the PSM hazard functions
205205
#' @description Graph the PSM hazard functions
206206
#' @inheritParams pickout_psmhaz
207+
#' @param ptdata Dataset of patient level data. Must be a tibble with columns named:
208+
#' - ptid: patient identifier
209+
#' - pfs.durn: duration of PFS from baseline
210+
#' - pfs.flag: event flag for PFS (=1 if progression or death occurred, 0 for censoring)
211+
#' - os.durn: duration of OS from baseline
212+
#' - os.flag: event flag for OS (=1 if death occurred, 0 for censoring)
213+
#' - ttp.durn: duration of TTP from baseline (usually should be equal to pfs.durn)
214+
#' - ttp.flag: event flag for TTP (=1 if progression occurred, 0 for censoring).
207215
#' @inherit pickout_psmhaz return
208216
#' @importFrom rlang .data
209217
#' @export

R/resmeans.R

+11-9
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ calc_rmd_first <- function(ds, cuttime) {
431431

432432
#' Calculate restricted mean durations for each health state and all three models
433433
#' @description Calculate restricted mean durations for each health state (progression free and progressed disease) for all three models (partitioned survival, clock forward state transition model, clock reset state transition model).
434-
#' @param simdat Dataset of patient level data. Must be a tibble with columns named:
434+
#' @param ptdata Dataset of patient level data. Must be a tibble with columns named:
435435
#' - ptid: patient identifier
436436
#' - pfs.durn: duration of PFS from baseline
437437
#' - pfs.flag: event flag for PFS (=1 if progression or death occurred, 0 for censoring)
@@ -471,7 +471,7 @@ calc_rmd_first <- function(ds, cuttime) {
471471
#' calc_allrmds(bosonc, dpam=params)
472472
#' # RMD using discretized ("disc") method, no lifetable constraint
473473
#' calc_allrmds(bosonc, dpam=params, rmdmethod="disc", timestep=1)
474-
calc_allrmds <- function(simdat,
474+
calc_allrmds <- function(ptdata,
475475
inclset = 0,
476476
dpam,
477477
psmtype = "simple",
@@ -481,14 +481,16 @@ calc_allrmds <- function(simdat,
481481
discrate = 0,
482482
rmdmethod = "int",
483483
timestep = 1) {
484+
# Set-up variables
485+
484486
# Check calculations valid
485487
chvalid <- is.na(dpam[1])==FALSE
486488
if (chvalid==FALSE) stop("No validly fitted endpoints")
487489
# For a bootstrap sample, refit all distributions
488490
if (inclset[1]!=0) {
489-
dpam <- fit_ends_mods_given(simdat[inclset,], dpam, cuttime)
491+
dpam <- fit_ends_mods_given(ptdata[inclset,], dpam, cuttime)
490492
} else {
491-
ds <- create_extrafields(simdat, cuttime)
493+
ds <- create_extrafields(ptdata, cuttime)
492494
}
493495
# Two piece adjustment if cutime>0
494496
if (cuttime>0) {
@@ -510,7 +512,7 @@ calc_allrmds <- function(simdat,
510512
pd_stmcr <- prmd_pd_stm_cr(dpam, Ty=adjTy, starting=starting, discrate=discrate)
511513
} else if (rmdmethod=="disc") {
512514
if (cuttime>0) {stop("Cannot calculate discretized RMD for two-piece models")}
513-
psm_drmd <- drmd_psm(ptdata=bosonc, dpam, psmtype=psmtype, Ty=Ty, discrate=discrate, lifetable=lifetable, timestep=timestep)
515+
psm_drmd <- drmd_psm(ptdata=ptdata, dpam, psmtype=psmtype, Ty=Ty, discrate=discrate, lifetable=lifetable, timestep=timestep)
514516
stmcf_drmd <- drmd_stm_cf(dpam, Ty=Ty, discrate=discrate, lifetable=lifetable, timestep=timestep)
515517
stmcr_drmd <- drmd_stm_cr(dpam, Ty=Ty, discrate=discrate, lifetable=lifetable, timestep=timestep)
516518
pf_psm <- psm_drmd$pf
@@ -552,16 +554,16 @@ calc_allrmds <- function(simdat,
552554
#' pps_cf = find_bestfit_spl(fits$pps_cf, "aic")$fit,
553555
#' pps_cr = find_bestfit_spl(fits$pps_cr, "aic")$fit
554556
#' )
555-
#' calc_allrmds_boot(simdat=bosonc, dpam=params)
556-
calc_allrmds_boot <- function(simdat,
557+
#' calc_allrmds_boot(ptdata=bosonc, dpam=params)
558+
calc_allrmds_boot <- function(ptdata,
557559
inclset = 0,
558560
dpam,
559561
cuttime = 0,
560562
Ty = 10,
561563
lifetable = NA,
562564
discrate = 0) {
563-
if (inclset[1]==0) {inclset <- 1:length(simdat$ptid)}
564-
mb <- calc_allrmds(simdat = simdat,
565+
if (inclset[1]==0) {inclset <- 1:length(ptdata$ptid)}
566+
mb <- calc_allrmds(ptdata = ptdata,
565567
inclset = inclset,
566568
dpam = dpam,
567569
cuttime = cuttime,

man/calc_allrmds.Rd

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/calc_allrmds_boot.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/drmd_psm.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/drmd_stm_cr.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/graph_psm_hazards.Rd

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/example.Rmd

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ First we need to install and load the packages of interest (with thanks to @vbal
2424
# Install psm3mkv version 0.2 from github
2525
require("remotes")
2626
remotes::install_github("Merck/psm3mkv",
27-
ref="v0.2",
28-
build_vignettes=TRUE)
27+
ref="Nextrel",
28+
build_vignettes=FALSE)
2929
3030
# First specify the packages of interest
3131
packages = c("psm3mkv", "dplyr", "boot", "ggsci", "flexsurv", "survival")
@@ -185,7 +185,7 @@ The Brier score is a measure of goodness of fit of a survival model at a particu
185185
The *psm3mkv* package allows examination of Integrated Brier Scores in the fit of Overall Survival by each of the model structures.
186186

187187
```{r brier}
188-
calc_ibs(bosonc, params)
188+
# calc_ibs(bosonc, params)
189189
```
190190
In this case, the IBS calculation involved integrating between times 1.18 and 52.70. The PSM had the least IBS and best fit (IBS=0.1771); the two STMs had slightly greater IBS values (0.1773 for CF and 0.1776 for CR).
191191

0 commit comments

Comments
 (0)