diff --git a/R/corPFSOS.R b/R/corPFSOS.R index 65cf6a9e..fbaaf060 100644 --- a/R/corPFSOS.R +++ b/R/corPFSOS.R @@ -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 @@ -291,34 +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 <- corTrans(transition) + res <- list("corPFSOS" = corTrans(transition)) if (bootstrap) { future::plan(future::multisession, workers = max(1, parallel::detectCores() - 1)) - ids <- lapply(1:bootstrap.n, function(x) sample(seq_len(nrow(data)), nrow(data), replace = TRUE)) + 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, ] + 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 + lowerQuantile <- (1 - bootstrap_level) / 2 + upperQuantile <- lowerQuantile + bootstrap_level c(stats::quantile(corBootstrap, lowerQuantile), "corPFSOS" = res, stats::quantile(corBootstrap, upperQuantile) ) - } else { - c("corPFSOS" = res) + res$lower <- stats::quantile(corBootstrap, lowerQuantile) + res$upper <- stats::quantile(corBootstrap, upperQuantile) } + res } diff --git a/man/corPFSOS.Rd b/man/corPFSOS.Rd index 5d94df67..e3210005 100644 --- a/man/corPFSOS.Rd +++ b/man/corPFSOS.Rd @@ -8,8 +8,8 @@ corPFSOS( data, transition, bootstrap = TRUE, - bootstrap.n = 100, - bootstrap.level = 0.95 + bootstrap_n = 100, + bootstrap_level = 0.95 ) } \arguments{ @@ -21,9 +21,9 @@ See \code{\link[=exponential_transition]{exponential_transition()}} or \code{\li \item{bootstrap}{(\code{flag})\cr if \code{TRUE} computes confidence interval via bootstrap.} -\item{bootstrap.n}{(\code{count})\cr number of bootstrap samples.} +\item{bootstrap_n}{(\code{count})\cr number of bootstrap samples.} -\item{bootstrap.level}{(\code{proportion})\cr confidence level for the confidence interval.} +\item{bootstrap_level}{(\code{proportion})\cr confidence level for the confidence interval.} } \value{ The correlation of PFS and OS.