Skip to content

Commit

Permalink
- vignett simulation comparison finalized
Browse files Browse the repository at this point in the history
- modified assessDesign so that the modelling part becomes optional
- minor code fixes
  • Loading branch information
wojcieko committed Feb 4, 2025
1 parent 7d7a2b1 commit 231e13c
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 248 deletions.
40 changes: 29 additions & 11 deletions R/BMCPMod.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @title assessDesign
#'.
#'
#' @description This function performs simulation based trial design evaluations for a set of specified dose-response models

Check warning on line 3 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=3,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 124 characters.
#'
#' @param n_patients Vector specifying the planned number of patients per dose group

Check warning on line 5 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=5,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 84 characters.
Expand All @@ -8,6 +8,7 @@
#' @param sd A positive value, specification of assumed sd
#' @param n_sim Number of simulations to be performed
#' @param alpha_crit_val (Un-adjusted) Critical value to be used for the MCP testing step. Passed to the getCritProb() function for the calculation of adjusted critical values (on the probability scale). Default is 0.05.

Check warning on line 10 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=10,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 220 characters.
#' @param modelling Boolean variable defining whether the Mod part of Bayesian MCP-Mod will be performed in the assessment. More heavy on ressources. Default FALSE.

Check warning on line 11 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=11,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 164 characters.
#' @param simple Boolean variable defining whether simplified fit will be applied. Passed to the getModelFits function. Default FALSE.

Check warning on line 12 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=12,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 134 characters.
#' @param reestimate Boolean variable defining whether critical value should be calculated with re-estimated contrasts (see getCritProb function for more details). Default FALSE

Check warning on line 13 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=13,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 177 characters.
#' @param contr An object of class 'optContr' as created by the getContr() function. Allows specification of a fixed contrasts matrix. Default NULL

Check warning on line 14 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=14,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 147 characters.
Expand Down Expand Up @@ -54,6 +55,7 @@ assessDesign <- function (

n_sim = 1e3,
alpha_crit_val = 0.05,
modelling = FALSE,
simple = TRUE,
reestimate = FALSE,

Expand All @@ -69,6 +71,7 @@ assessDesign <- function (
checkmate::check_double(n_sim, lower = 1, upper = Inf)
checkmate::check_double(alpha_crit_val, lower = 0, upper = 1)
checkmate::check_logical(simple)
checkmate::check_logical(modelling)
# TODO: check that prior_list has 'sd_tot' attribute, and that it's numeric # this is not applicable at the moment

dose_levels <- attr(mods, "doses")
Expand Down Expand Up @@ -115,19 +118,34 @@ assessDesign <- function (
sd_posterior = post_sd))

}

b_mcp_mod <- performBayesianMCPMod(
posterior_list = posterior_list,
contr = contr,
crit_prob_adj = crit_prob_adj,
simple = simple)

if (identical(modelling, FALSE)) {

b_mcp <- performBayesianMCP(
posterior_list = posterior_list,
contr = contr,
crit_prob_adj = crit_prob_adj)

} else {

b_mcp_mod <- performBayesianMCPMod(
posterior_list = posterior_list,
contr = contr,
crit_prob_adj = crit_prob_adj,
simple = simple)

}

})

avg_success_rate <- mean(sapply(eval_design, function (bmcpmod) {
attr(bmcpmod$BayesianMCP, "successRate")
avg_success_rate <- mean(sapply(eval_design, function (x) {

ifelse(identical(modelling, FALSE),
attr(x, "successRate"),
attr(x$BayesianMCP, "successRate"))

}))

names(eval_design) <- model_names

attr(eval_design, "avgSuccessRate") <- avg_success_rate
Expand Down Expand Up @@ -156,7 +174,7 @@ assessDesign <- function (
#' 2) Frequentist approach: If only dose_weights are provided optimal contrast vectors are calculated from the
#' regular MCPMod for these specific weights
#' 3) Bayesian approach + re-estimation: If only a sd_posterior (i.e. variability of the posterior distribution) is provided, pseudo-optimal contrasts based on these posterior weights will be calculated
#' 4) Frequentist approach+re-estimation:If only a se_new_trial (i.e. the estimated variability per dose group of a new trial) is provided, optimal contrast vectors are calculated from the
#' 4) Frequentist approach+re-estimation: If only a se_new_trial (i.e. the estimated variability per dose group of a new trial) is provided, optimal contrast vectors are calculated from the
#' regular MCPMod for this specific vector of standard errors. For the actual evaluation this vector of standard errors is translated into a (diagonal) matrix of variances
#'
#' @param mods An object of class 'Mods' as created by the function 'DoseFinding::Mods()'
Expand Down
2 changes: 0 additions & 2 deletions R/posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ getPosteriorI <- function(
#' @title getESS
#'
#' @description This function calculates the effective sample size for every dose group via the RBesT function ess().
#'
#' @param post_list A posterior list object, for which the effective sample size for each dose group should be calculated
#'
#' @return A vector of the effective sample sizes for each dose group
#'
#' @export
Expand Down
Binary file added inst/extdata/results_BayesianMCPMod_conv.rds
Binary file not shown.
Binary file added inst/extdata/results_BayesianMCPMod_eff.rds
Binary file not shown.
Binary file added inst/extdata/results_MCPModPack_conv.rds
Binary file not shown.
Binary file added inst/extdata/results_MCPModPack_eff.rds
Binary file not shown.
Loading

0 comments on commit 231e13c

Please sign in to comment.