Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/restructure #1

Merged
merged 48 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
2346035
- initial test commit
wojcieko Sep 5, 2023
d2cf056
- feature restructuring done
wojcieko Sep 15, 2023
ad2a638
- removed helper.R, became superflouos
wojcieko Sep 15, 2023
6e12c0c
- updated documentation
wojcieko Sep 15, 2023
602dd76
Create dummy vignette
sebastianbossert Sep 22, 2023
80a80ad
- small bug fix for significance test
wojcieko Sep 22, 2023
6b2beb0
fixed warnings in cmd check
Xyarz Sep 25, 2023
8467e27
First draft vignette - including only test step
sebastianbossert Sep 29, 2023
585a215
- included plot function
wojcieko Oct 4, 2023
644ec5c
-fixed typo in plot function
wojcieko Oct 4, 2023
cee4363
- getPosterior can now take custom vectors for mu and sd
wojcieko Oct 4, 2023
63dfec0
- for single set of simulated data (e.g. observed data), getPosterior…
wojcieko Oct 4, 2023
4222181
Inclusion of model fits.
sebastianbossert Oct 5, 2023
5e43277
Addition of (minimum) explanation text to vignette
sebastianbossert Oct 5, 2023
5d4d121
Merge pull request #2 from Boehringer-Ingelheim/feature/vignettes
sebastianbossert Oct 6, 2023
13ebcb2
Correction of two minor bugs in the vignette file.
sebastianbossert Oct 6, 2023
489e049
Merge branch 'feature/restructure' of https://github.com/Boehringer-I…
Xyarz Oct 9, 2023
7dc310b
fixed github action errors
Xyarz Oct 9, 2023
497a709
added missing dependency
Xyarz Oct 9, 2023
a5cd793
styled vignette!
Xyarz Oct 9, 2023
973c313
added tests
Xyarz Oct 9, 2023
5c852d7
added missing dependency
Xyarz Oct 9, 2023
ff4bb34
added covr workflow and badges
Xyarz Oct 10, 2023
209aed4
adjusted covr yaml
Xyarz Oct 10, 2023
4893c8b
added pkgdown yaml
Xyarz Oct 10, 2023
107b9a0
removed error
Xyarz Oct 10, 2023
a1a34ac
alter ref
Xyarz Oct 10, 2023
773e138
- interim commit to enable pulling latest updated
wojcieko Oct 10, 2023
84f0c91
- included bootstrapping credible bands
wojcieko Oct 12, 2023
3088a10
- adapted vignette to new plot function
wojcieko Oct 12, 2023
c375ffe
- fixed changes in plot test file due to re-naming
wojcieko Oct 12, 2023
ccd270b
- devtools::check() pleasing
wojcieko Oct 12, 2023
89fd571
adjusted bootstrapping.R line, error in Vignette as well as created t…
Xyarz Oct 13, 2023
f5f4913
- typo correction in bootstrapping function
wojcieko Oct 13, 2023
cedb075
adjusted tests
Xyarz Oct 13, 2023
acd3f82
- added color for bootstrap credible bands (and median) in plot_model…
wojcieko Oct 13, 2023
cce6014
Merge branch 'feature/restructure' of https://github.com/Boehringer-I…
wojcieko Oct 13, 2023
9eba0fc
adjusted test calls
Xyarz Oct 13, 2023
aa1f665
- corrected typo on bootstrap tests
wojcieko Oct 13, 2023
a391f99
Merge branch 'feature/restructure' of https://github.com/Boehringer-I…
wojcieko Oct 13, 2023
eddb111
- introduced S3 methods for modelFits and postList: plot and predict …
wojcieko Oct 13, 2023
7f516af
- corrected typo in predict.ModelFit()
wojcieko Oct 13, 2023
db33d70
- added S3 printing methods for BayesianMCP, BayesianMCPMod, modelFits
wojcieko Oct 14, 2023
c332b7a
- added function assessDesign()
wojcieko Oct 14, 2023
a1ed96d
- added new functions getContrMat, getCritProb, getPriorList
wojcieko Oct 14, 2023
b45e0b2
Vignette update (other trial example, making use of newly available f…
sebastianbossert Oct 16, 2023
31ebd7f
New draft vignette around simulation added
sebastianbossert Oct 18, 2023
09b214b
Further updates in vignettes.
sebastianbossert Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_CONFIG_SANDBOX_ENABLED: false

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: covr

- name: Install BayesianMCPMod
shell: bash
run: R CMD INSTALL --preclean .

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
14 changes: 11 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: BayesianMCPMod
Title: Bayesian MCPMod
Version: 0.1.3
Version: 0.1.3-1
Authors@R: c(
person("Sebastian", "Bossert",
role = "aut",
Expand All @@ -22,11 +22,19 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Imports:
DoseFinding,
ggplot2,
stats,
RBesT,
nloptr
nloptr,
clinDR,
knitr,
rmarkdown,
dplyr
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Depends:
R (>= 4.1)
VignetteBuilder: knitr
Config/testthat/edition: 3
URL: https://github.com/Boehringer-Ingelheim/BayesianMCPMod
BugReports: https://github.com/Boehringer-Ingelheim/BayesianMCPMod/issues
8 changes: 4 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(BMCPMod)
export(doFit)
export(estimateModels)
export(getGenAICs)
export(postShape)
export(getBootsrapBands)
export(getModelFits)
export(getPosterior)
export(plot_modelFits)
export(simulateData)
73 changes: 54 additions & 19 deletions R/BMCPMod.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,61 @@
#' @title BMCPMod
#' @param ancova1 tbd
#'
#' @param cont_Mat1 tbd
#'

Check warning on line 2 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=2,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @param posteriors_list tbd
#' @param contr_mat tbd
#' @param crit_prob tbd
#' @param n_simulations tbd
#'
#'

Check warning on line 6 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=6,col=3,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' @export
BMCPMod <- function(

Check warning on line 8 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=8,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols.
ancova1,
cont_Mat1,
crit_prob,
n_simulations) {
adj1_p <- list()

Check warning on line 9 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=9,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
posteriors_list,
contr_mat,
crit_prob

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=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
) {

Check warning on line 15 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=15,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
lapply(posteriors_list, BayesMCPMod, contr_mat, crit_prob)

Check warning on line 17 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=17,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
}

for (i in 1:n_simulations) {
ancova <- ancova1[[i]]
adj1_p[[i]] <- BayesMCPMod(
ancova,
cont_Mat1,
crit_prob
)
BayesMCPMod <- function (

Check warning on line 20 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=20,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols.

Check warning on line 20 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=20,col=24,[function_left_parentheses_linter] Remove spaces before the left parenthesis in a function definition.

Check warning on line 21 in R/BMCPMod.R

View workflow job for this annotation

GitHub Actions / lint

file=R/BMCPMod.R,line=21,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
posterior_i,
contr_mat,
crit_prob

) {

getPostProb <- function (

contr_j, # j: dose level
post_combs_i # i: simulation outcome

) {

## Test statistic = sum over all components of
## posterior weight * normal probability distribution of
## critical values for doses * estimated mean / sqrt(product of critical values for doses)

## Calculation for each component of the posterior
contr_theta <- apply(post_combs_i$means, 1, `%*%`, contr_j)
contr_var <- apply(post_combs_i$vars, 1, `%*%`, contr_j^2)
contr_weights <- post_combs_i$weights

## P(c_m * theta > 0 | Y = y) for a shape m (and dose j)
post_probs <- sum(contr_weights * stats::pnorm(contr_theta / sqrt(contr_var)))

return (post_probs)

}

return(adj1_p)

post_combs_i <- getPostCombsI(posterior_i)
post_probs <- apply(contr_mat$contMat, 2, getPostProb, post_combs_i)

res_list <- list(
sign = ifelse(max(post_probs) > crit_prob, 1, 0),
p_val = max(post_probs),
post_probs = post_probs)

return (res_list)

}
92 changes: 92 additions & 0 deletions R/bootstrapping.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#' @title getBootsrapBands
#'
#' @param model_fits tbd
#' @param n_samples tbd
#' @param alpha tbd
#' @param avg_fit tbd
#' @param dose_seq tbd
#'
#' @return tbd
#' @export
getBootsrapBands <- function (

model_fits,
n_samples = 1e3,
alpha = c(0.05, 0.5),
avg_fit = TRUE,
dose_seq = NULL

) {

mu_hat_samples <- sapply(attr(model_fits, "posterior"),
RBesT::rmix, n = n_samples)
sd_hat <- summary.postList(attr(model_fits, "posterior"))[, 2]

dose_levels <- model_fits[[1]]$dose_levels
model_names <- names(model_fits)
quantile_probs <- sort(unique(c(alpha / 2, 1 - alpha / 2)))

if (is.null(dose_seq)) {

dose_seq <- seq(min(dose_levels), max(dose_levels), length.out = 100L)

}

preds <- apply(mu_hat_samples, 1, function (mu_hat) {

preds_mu_hat <- sapply(model_names, function (model) {

fit <- DoseFinding::fitMod(
dose = model_fits[[1]]$dose_levels,
resp = mu_hat,
S = diag(sd_hat^2),
model = model,
type = "general",
bnds = DoseFinding::defBnds(
mD = max(model_fits[[1]]$dose_levels))[[model]])

preds <- stats::predict(fit, doseSeq = dose_seq, predType = "ls-means")
attr(preds, "gAIC") <- DoseFinding::gAIC(fit)

return (preds)

}, simplify = FALSE)

preds_mu_mat <- do.call(rbind, preds_mu_hat)

if (avg_fit) {

avg_fit_indx <- which.min(sapply(preds_mu_hat, attr, "gAIC"))
preds_mu_mat <- rbind(preds_mu_mat, avgFit = preds_mu_mat[avg_fit_indx, ])

}

return (preds_mu_mat)

})

if (avg_fit) {

model_names <- c(model_names, "avgFit")

}

sort_indx <- order(rep(seq_along(model_names), length(dose_seq)))
quant_mat <- t(apply(X = preds[sort_indx, ],
MARGIN = 1,
FUN = stats::quantile,
probs = quantile_probs))

cr_bounds_data <- cbind(
dose_seqs = dose_seq,
models = rep(
x = factor(model_names,
levels = c("linear", "emax", "exponential",
"sigEmax", "logistic", "quadratic",
"avgFit")),
each = length(dose_seq)),
as.data.frame(quant_mat))

return (cr_bounds_data)

}
43 changes: 0 additions & 43 deletions R/dataSimulation.R

This file was deleted.

Loading
Loading