Skip to content

Commit

Permalink
- Fixed a bug that would lead to success rates for the models not pri…
Browse files Browse the repository at this point in the history
…nted correctly with print.BayesianMCPMod() in case more than 1 model of the same family was tested, e.g. 2 different shapes of sigEmax
  • Loading branch information
wojcieko committed Apr 9, 2024
1 parent bab9290 commit a17f3e6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 41 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: BayesianMCPMod
Title: Simulate, Evaluate, and Analyze Dose Finding Trials with Bayesian
MCPMod
Version: 1.0.1
Version: 1.0.2
Authors@R: c(
person("Boehringer Ingelheim Pharma GmbH & Co. KG", role = c("cph", "fnd")),
person("Stephan", "Wojciekowski", , "[email protected]", role = c("aut", "cre")),
Expand Down
23 changes: 16 additions & 7 deletions R/BMCPMod.R
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,6 @@ performBayesianMCPMod <- function (

}

if (inherits(posterior_list, "postList")) {

posterior_list <- list(posterior_list)

}

if (inherits(contr, "optContr")) {

model_shapes <- colnames(contr$contMat)
Expand Down Expand Up @@ -548,11 +542,26 @@ performBayesianMCP <- function(

})))


return (b_mcp)

}

getModelSuccesses <- function (b_mcp) {

stopifnot(inherits(b_mcp, "BayesianMCP"))

model_indices <- grepl("post_probs.", colnames(b_mcp))
model_names <- colnames(b_mcp)[model_indices] |>
sub(pattern = "post_probs.", replacement = "", x = _)

model_successes <- colMeans(b_mcp[, model_indices] > b_mcp[, "crit_prob_adj"])

names(model_successes) <- model_names

return (model_successes)

}

BayesMCPi <- function (

posterior_i,
Expand Down
46 changes: 13 additions & 33 deletions R/s3methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,7 @@ print.BayesianMCPMod <- function (

) {

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

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

if (!is.null(y)) {

sapply(y, function (z) z$significant)

} else {

model_signs <- rep(FALSE, length(model_names))
names(model_signs) <- model_names

return (model_signs)

}

})))

print(x$BayesianMCP)
cat("\n")
cat("Model Significance Frequencies\n")
print(model_success, ...)

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

cat("Average Posterior ESS\n")
print(attr(x$BayesianMCP, "ess_avg"), ...)

}

}

Expand All @@ -57,6 +24,8 @@ print.BayesianMCP <- function (

n_sim <- nrow(x)

model_successes <- getModelSuccesses(x)

cat("Bayesian Multiple Comparison Procedure\n")

if (n_sim == 1L) {
Expand All @@ -74,6 +43,17 @@ print.BayesianMCP <- function (

}

cat("\n")
cat("Model Significance Frequencies\n")
print(model_successes, ...)

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

cat("Average Posterior ESS\n")
print(attr(x, "ess_avg"), ...)

}

}

## ModelFits ----------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions vignettes/analysis_normal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ It is possible to plot the fitted dose response models and an AIC based average
plot(fit_simple)
plot(fit)
```

To assess the uncertainty, one can additionally visualize credible bands (orange shaded areas, default levels are 50% and 95%).
These credible bands are calculated with a bootstrap method as follows:
Samples from the posterior distribution are drawn and for every sample the simplified fitting step and a prediction is performed.
These predictions are then used to identify and visualize the specified quantiles.
```{r Plot with bootstrap}
plot(fit, cr_bands = TRUE)
```

The bootstrap based quantiles can also be directly calculated via the getBootstrapQuantiles() function.
For this example, only 6 quantiles are bootstrapped for each model fit.
```{r Bootstrap}
Expand Down

0 comments on commit a17f3e6

Please sign in to comment.