Skip to content

Commit

Permalink
Add bootstrap (#94)
Browse files Browse the repository at this point in the history
Fixes #93

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
holgstr and github-actions[bot] authored Nov 27, 2023
1 parent 43194b2 commit 99c897a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ Depends:
R (>= 3.6)
Imports:
checkmate,
furrr,
future,
mstate,
parallelly,
stats,
survival
Suggests:
Expand Down
40 changes: 30 additions & 10 deletions R/corPFSOS.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ p11Integ <- function(x, transition) {
#' see [exponential_transition()], [weibull_transition()] or [piecewise_exponential()] for details.
#' @param s (`numeric`)\cr lower time point.
#' @param t (`numeric`)\cr higher time point.
#' @return This returns the natural logarithm of the probability of remaining in progression (state 1) between two time points,
#' conditional on being in state 1 at the lower time point.
#' @return This returns the natural logarithm of the probability of remaining in progression (state 1)
#' between two time points, conditional on being in state 1 at the lower time point.
#'
#' @export
#'
Expand Down Expand Up @@ -277,8 +277,8 @@ corTrans <- function(transition) {
#' Initial parameters for optimization can be specified here.
#' See [exponential_transition()] or [weibull_transition()] for details.
#' @param bootstrap (`flag`)\cr if `TRUE` computes confidence interval via bootstrap.
#' @param bootstrap.n (`count`)\cr number of bootstrap samples.
#' @param bootstrap.level (`proportion`)\cr confidence level for the confidence interval.
#' @param bootstrap_n (`count`)\cr number of bootstrap samples.
#' @param bootstrap_level (`proportion`)\cr confidence level for the confidence interval.
#'
#' @return The correlation of PFS and OS.
#' @export
Expand All @@ -291,15 +291,35 @@ corTrans <- function(transition) {
#' accrual = list(param = "intensity", value = 7)
#' )[[1]]
#' corPFSOS(data, transition)
corPFSOS <- function(data, transition, bootstrap = TRUE, bootstrap.n = 100, bootstrap.level = 0.95) {
corPFSOS <- function(data, transition, bootstrap = TRUE, bootstrap_n = 100, bootstrap_level = 0.95) {
assert_data_frame(data)
assert_flag(bootstrap)
assert_count(bootstrap.n)
assert_number(bootstrap.level, lower = 0.01, upper = 0.999)
assert_count(bootstrap_n)
assert_number(bootstrap_level, lower = 0.01, upper = 0.999)

trans <- estimateParams(data, transition)
res <- list("corPFSOS" = corTrans(transition))
if (bootstrap) {
# insert bootstrap here
} else {
corTrans(trans)
future::plan(future::multisession, workers = max(1, parallelly::availableCores() - 1))
ids <- lapply(1:bootstrap_n, function(x) sample(seq_len(nrow(data)), nrow(data), replace = TRUE))
corBootstrap <- furrr::future_map_dbl(ids, ~ {
furrr::furrr_options(
globals = list(data = data, transition = transition),
packages = c("simIDM")
)
b_sample <- data[.x, , drop = FALSE]
prepared_data <- prepareData(b_sample)
b_transition <- estimateParams(b_sample, transition)
corTrans(b_transition)
})
lowerQuantile <- (1 - bootstrap_level) / 2
upperQuantile <- lowerQuantile + bootstrap_level
c(stats::quantile(corBootstrap, lowerQuantile),
"corPFSOS" = res,
stats::quantile(corBootstrap, upperQuantile)
)
res$lower <- stats::quantile(corBootstrap, lowerQuantile)
res$upper <- stats::quantile(corBootstrap, upperQuantile)
}
res
}
8 changes: 4 additions & 4 deletions man/corPFSOS.Rd

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

4 changes: 2 additions & 2 deletions man/log_p11.Rd

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

0 comments on commit 99c897a

Please sign in to comment.