Skip to content

Commit

Permalink
- updated getContr()
Browse files Browse the repository at this point in the history
  • Loading branch information
wojcieko committed Dec 7, 2023
1 parent 7a0dac7 commit ff9a940
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 42 deletions.
80 changes: 66 additions & 14 deletions R/BMCPMod.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ assessDesign <- function (
mods,
prior_list,

sd = NULL,

n_sim = 1e3,
alpha_crit_val = 0.05,
simple = TRUE

) {

dose_levels <- attr(prior_list, "dose_levels")
sd <- ifelse(is.null(sd), attr(prior_list, "sd_tot"), sd)

stopifnot(
"sd length must coincide with number of dose levels" =
length(sd) == length(dose_levels))

data <- simulateData(
n_patients = n_patients,
dose_levels = dose_levels,
sd = attr(prior_list, "sd_tot"),
sd = sd,
mods = mods,
n_sim = n_sim)

Expand All @@ -43,7 +50,7 @@ assessDesign <- function (
dose_weights = n_patients,
alpha_crit_val = alpha_crit_val)

contr_mat_prior <- getContrMat(
contr_mat_prior <- getContr(
mods = mods,
dose_levels = dose_levels,
dose_weights = n_patients,
Expand All @@ -63,31 +70,75 @@ assessDesign <- function (

}

#' @title getContrMat
#' @title getContr
#'
#' @param mods tbd
#' @param dose_levels tbd
#' @param dose_weights tbd
#' @param prior_list tbd
#' @param se_new_trial tbd
#' @param sd_posterior tbd
#'
#' @export
getContrMat <- function (
getContr <- function (

mods,
dose_levels,
dose_weights,
prior_list
dose_weights = NULL,
prior_list = NULL,
se_new_trial = NULL,
sd_posterior = NULL

) {

ess_prior <- suppressMessages(round(unlist(lapply(prior_list, RBesT::ess))))
if (is.null(prior_list)) { # frequentist

if (!is.null(se_new_trial)) { # re-estimate, se_new_trial

w <- NULL
S <- diag((se_new_trial)^2)

} else { # do not re-estimate, dose_weights

w <- dose_weights
S <- NULL

}

} else { # Bayes

if (!is.null(sd_posterior)) { # re-estimate, sd_posterior

w <- NULL
S <- diag((sd_posterior)^2)

} else { # do not re-estimate, dose_weights + prior_list

w <- dose_weights +
suppressMessages(round(unlist(lapply(prior_list, RBesT::ess))))
S <- NULL

}

}

contr_mat <- DoseFinding::optContr(
models = mods,
doses = dose_levels,
w = dose_weights + ess_prior)
if (is.null(w)) {

contr <- DoseFinding::optContr(
models = mods,
doses = dose_levels,
S = S)

} else {

contr <- DoseFinding::optContr(
models = mods,
doses = dose_levels,
w = w)

}

return (contr_mat)
return (contr)

}

Expand Down Expand Up @@ -204,7 +255,7 @@ addSignificance <- function (

}

#' @title BayesianMCP
#' @title performBayesianMCP
#'
#' @param posteriors_list tbd
#' @param contr_mat tbd
Expand Down Expand Up @@ -270,7 +321,8 @@ BayesMCPi <- function (

res <- c(sign = ifelse(max(post_probs) > crit_prob, 1, 0),
p_val = max(post_probs),
post_probs = post_probs)
post_probs = post_probs,
crit_prob = crit_prob) # TODO attr crit_prob??

return (res)

Expand Down
6 changes: 6 additions & 0 deletions R/s3methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ print.BayesianMCP <- function (
cat(" Estimated Success Rate: ", power, "\n")
cat(" N Simulations: ", n_sim)

## TODO if n_nim == 1
# c(sign = ifelse(max(post_probs) > crit_prob, 1, 0),
# p_val = max(post_probs),
# post_probs = post_probs,
# crit_prob = crit_prob)

}

## ModelFits ----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion R/simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ getModelData <- function (

return (model_data)

}
}
1 change: 1 addition & 0 deletions man/assessDesign.Rd

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

31 changes: 31 additions & 0 deletions man/getContr.Rd

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

20 changes: 0 additions & 20 deletions man/getContrMat.Rd

This file was deleted.

8 changes: 4 additions & 4 deletions man/getPosterior.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/performBayesianMCP.Rd

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

2 changes: 1 addition & 1 deletion vignettes/analysis_normal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ crit_pval <- getCritProb(
dose_weights = n_patients,
alpha_crit_val = 0.1)
contr_mat_prior <- getContrMat(
contr_mat_prior <- getContr(
mods = mods,
dose_levels = dose_levels,
dose_weights = n_patients,
Expand Down

0 comments on commit ff9a940

Please sign in to comment.