Skip to content

Commit

Permalink
Additional check() fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Muston committed Sep 9, 2023
1 parent e029b2c commit b671edd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ create_dummydata_flexbosms <- function() {
) |>
dplyr::select(id, pfs.durn, pfs.flag,
os.durn, os.flag, ttp.durn, ttp.flag) |>
dplyr::rename(ptid = .data$id)
dplyr::rename(ptid = "id")
}
11 changes: 10 additions & 1 deletion R/ppdpps.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#' @examples
#' bosonc <- create_dummydata("flexbosms")
#' fits <- fit_ends_mods_spl(bosonc)
#' Pick out best distribution according to min AIC
#' # Pick out best distribution according to min AIC
#' params <- list(
#' ppd = find_bestfit_spl(fits$ppd, "aic")$fit,
#' ttp = find_bestfit_spl(fits$ttp, "aic")$fit,
Expand All @@ -44,6 +44,13 @@
#' calc_haz_psm(0:10, ptdata=bosonc, dpam=params, type="simple")
#' calc_haz_psm(0:10, ptdata=bosonc, dpam=params, type="complex")
calc_haz_psm <- function(timevar, ptdata, dpam, type) {
# Declare local variables
pfs.ts <- pfs.type <- pfs.spec <- NULL
os.ts <- os.type <- os.spec <- NULL
ttp.ts <- ttp.type <- ttp.spec <- NULL
ne_pfs <- ne_ttp <- progfrac <- NULL
http <- hpf <- hos <- sos <- spf <- NULL
hppd_simple <- hppd_complex <- hppd <- hpps <- hdiff <- NULL
# PFS
pfs.ts <- convert_fit2spec(dpam$pfs)
pfs.type <- pfs.ts$type
Expand Down Expand Up @@ -104,6 +111,8 @@ calc_haz_psm <- function(timevar, ptdata, dpam, type) {
#' dpam=params,
#' type="simple")
calc_surv_psmpps <- function(totime, fromtime=0, ptdata, dpam, type="simple") {
# Declare local variables
cumH <- NULL
# Hazard function
hazfn <- function(x) {
calc_haz_psm(timevar=x, ptdata=ptdata, dpam=dpam, type=type)$post
Expand Down
8 changes: 4 additions & 4 deletions R/resmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,16 @@ calc_allrmds <- function(simdat,
pfdat <- tidyr::as_tibble(cbind(time=pf_km$time, surv=pf_km$surv)) |>
dplyr::mutate(
row = dplyr::row_number(),
itime = if_else(.data$row==1, .data$time, time-lag(.data$time)),
incl = if_else(.data$time<cuttime, 1, 0),
itime = dplyr::if_else(.data$row==1, .data$time, .data$time-dplyr::lag(.data$time)),
incl = dplyr::if_else(.data$time<cuttime, 1, 0),
area = .data$incl*.data$surv*.data$itime
)
pfarea <- sum(pfdat$area)
pfsurv <- min(pfdat[pfdat$incl==1,]$surv)
# OS calculations
osdat <- tidyr::as_tibble(cbind(time=os_km$time, surv=os_km$surv)) |>
mutate(
row = row_number(),
dplyr::mutate(
row = dplyr::row_number(),
itime = if_else(.data$row==1, .data$time, .data$time-lag(.data$time)),
incl = if_else(.data$time<cuttime, 1, 0),
area = .data$incl*.data$surv*.data$itime
Expand Down
2 changes: 1 addition & 1 deletion man/calc_haz_psm.Rd

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

8 changes: 4 additions & 4 deletions tests/testthat/test-resmeans.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ rmd_all <- calc_allrmds(bosonc,
Ty <- 10
Tw <- Ty * weeks_in_year
# params$pfs$dlist$name is "exp"
exp_psm_pf <- rmst_exp(Tw, rate=params$pfs$res[1])
exp_psm_pf <- flexsurv::rmst_exp(Tw, rate=params$pfs$res[1])
# params$os$dlist$name is "weibullPH"
exp_psm_os <- rmst_weibullPH(Tw, shape=params$os$res[1,1], scale=params$os$res[2,1])
exp_psm_os <- flexsurv::rmst_weibullPH(Tw, shape=params$os$res[1,1], scale=params$os$res[2,1])
exp_psm_pd <- exp_psm_os - exp_psm_pf

test_that("PSM results match expected durations", {
Expand Down Expand Up @@ -167,8 +167,8 @@ exp_stmcf_pf2 <- stats::integrate(int1, 0, 10*weeks_in_year)$value
S <- cbind(c(0,0),c(0, Tw),c(Tw, Tw))
exp_stmcr_pd2 <- SimplicialCubature::adaptIntegrateSimplex(int3, S)$integral
exp_stmcf_pd2 <- SimplicialCubature::adaptIntegrateSimplex(int2, S)$integral
exp_psm_pf2 <- rmst_exp(Tw, rate=params$pfs$res[1]) # Exp
exp_psm_os2 <- rmst_weibullPH(Tw,
exp_psm_pf2 <- flexsurv::rmst_exp(Tw, rate=params$pfs$res[1]) # Exp
exp_psm_os2 <- flexsurv::rmst_weibullPH(Tw,
shape=params$os$res[1,1],
scale=params$os$res[2,1]) # WeibullPH

Expand Down

0 comments on commit b671edd

Please sign in to comment.