Skip to content

Commit

Permalink
- fixed average success rate in assessDesign and added as attribute
Browse files Browse the repository at this point in the history
- added successRate attribute to BayesianMCP class objects
- fixed a warning in print function of BayesianMCPMod that would occur if more than 1 model shape of the same type was specified
  • Loading branch information
wojcieko committed Dec 14, 2023
1 parent 1ea587f commit 25f8f28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 10 additions & 4 deletions R/BMCPMod.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@ assessDesign <- function (

})

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

names(eval_design) <- model_names

attr(eval_design, "placEff") <- attr(mods, "placEff")
attr(eval_design, "maxEff") <- attr(mods, "maxEff")
attr(eval_design, "sampleSize") <- n_patients
attr(eval_design, "priorESS") <- getESS(prior_list)
attr(eval_design, "avgSuccessRate") <- avg_success_rate
attr(eval_design, "placEff") <- attr(mods, "placEff")
attr(eval_design, "maxEff") <- attr(mods, "maxEff")
attr(eval_design, "sampleSize") <- n_patients
attr(eval_design, "priorESS") <- getESS(prior_list)

return (eval_design)

Expand Down Expand Up @@ -347,6 +352,7 @@ performBayesianMCP <- function(

class(b_mcp) <- "BayesianMCP"
attr(b_mcp, "crit_prob_adj") <- crit_prob_adj
attr(b_mcp, "successRate") <- mean(b_mcp[, 1])
attr(b_mcp, "ess_avg") <- ifelse(
test = is.na(attr(posterior_list[[1]], "ess")),
yes = numeric(0),
Expand Down
10 changes: 6 additions & 4 deletions R/s3methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ print.BayesianMCPMod <- function (

model_names <- colnames(x$BayesianMCP)[
grepl("post_probs.", colnames(x$BayesianMCP))] |>
sub(pattern = "post_probs.", replacement = "", x = _)
sub(pattern = "post_probs.", replacement = "", x = _) |>
gsub(pattern = "\\d", replacement = "", x = _) |>
unique(x = _)

model_success <- colMeans(do.call(rbind, lapply(x$Mod, function (y) {

Expand All @@ -32,7 +34,7 @@ print.BayesianMCPMod <- function (
print(x$BayesianMCP)
cat("\n")
cat("Model Significance Frequencies\n")
print(c(avg = mean(model_success), model_success), ...)
print(model_success, ...)

if (!is.na(attr(x$BayesianMCP, "ess_avg"))) {

Expand All @@ -53,21 +55,21 @@ print.BayesianMCP <- function (

) {

power <- mean(x[, 1])
n_sim <- nrow(x)

cat("Bayesian Multiple Comparison Procedure\n")

if (n_sim == 1L) {

attr(x, "crit_prob_adj") <- NULL
attr(x, "success_rate") <- NULL
class(x) <- NULL

print.default(x, ...)

} else {

cat(" Estimated Success Rate: ", power, "\n")
cat(" Estimated Success Rate: ", attr(x, "successRate"), "\n")
cat(" N Simulations: ", n_sim)

}
Expand Down

0 comments on commit 25f8f28

Please sign in to comment.