Skip to content

Commit

Permalink
Updates around documentation of functions and vignette.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbossert committed Dec 18, 2023
1 parent f852df6 commit 1700b38
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 38 deletions.
23 changes: 15 additions & 8 deletions R/BMCPMod.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ assessDesign <- function (
#' 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 specified in the Dosefinding package.
#' @param dose_levels vector containing the different doseage levels.
#' @param dose_weights Vector specifying weights for the different doses. Please note that in case this information should be provided Default NULL
#' @param prior_list a prior_list object. Default NULL
#' @param sd_posterior a vector of positive numerics. Default NULL
#' @param se_new_trial a vector of positive numerics. Default NULL
#' @param dose_levels vector containing the different dosage levels.
#' @param dose_weights Vector specifying weights for the different doses. Please note that in case this information is provided together with a prior (i.e. Option i) is planned) these two inputs should be provided on the same scale (e.g. patient numbers). Default NULL
#' @param prior_list a prior_list object, only required as input for Option i). Default NULL
#' @param sd_posterior a vector of positive values with information about the variability of the posterior distribution, only required for Option iii). Default NULL
#' @param se_new_trial a vector of positive values with information about the observed variability, only required for Option iv). Default NULL
#'
#' @return contr Object of class ‘⁠optContr⁠’. A list containing entries contMat and muMat, and CorrMat. Specified in the Dosefinding package.
#'
Expand Down Expand Up @@ -196,11 +196,18 @@ getContr <- function (

#' @title getCritProb
#'
#' @description This function calculates multiplicity adjusted
#' @description This function calculates multiplicity adjusted critical values. The critical values are calculated in such a way that
#' when using non-informative priors the actual error level for falsely declaring a significant trial in the Bayesian MCPMod is controlled (by the specified alpha level).
#' Hereby optimal contrasts of the frequentist MCPMod are applied and two options can be distinguished
#' i) Frequentist approach: If only dose_weights are provided optimal contrast vectors are calculated from the
#' regular MCPMod for these specific weights and the corresponding critical value for this set of contrasts is calculated via the critVal function of the DoseFinding package.
#' ii) 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. Here as well the critical value for this set of contrasts is calculated via the critVal function of the DoseFinding package.
#'
#' @param mods An object of class "Mods" as specified in the Dosefinding package.
#' @param dose_levels vector containing the different dosage levels.
#' @param dose_weights Vector specifying weights for the different doses
#' @param dose_weights Vector specifying weights for the different doses, only required for Option i). Default NULL
#' @param se_new_trial a vector of positive values, only required for Option ii). Default NULL
#' @param alpha_crit_val significance level. Default set to 0.025.
#'
#' @return crit_pval multiplicity adjusted critical value on the probability scale.
Expand Down Expand Up @@ -339,7 +346,7 @@ addSignificance <- function (
#' @param contr a getContrMat object, contrast matrix to be used for the testing step.
#' @param crit_prob_adj a getCritProb object, specifying the critical value to be used for the testing (on the probability scale)
#'
#' @return b_mcp test result, with information about p-values for the individual dose-response shapes
#' @return b_mcp test result, with information about p-values for the individual dose-response shapes and overall significance
#'
#' @export
performBayesianMCP <- function(
Expand Down
11 changes: 9 additions & 2 deletions R/bootstrapping.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#' @title getBootstrapQuantiles
#'
#' @param model_fits tbd
#' @param quantiles tbd
#' @description A function to Calculate credible intervals to assess the uncertainty for the model fit. one can in addition visualize credible intervals (yellow shaded areas, the default is set to 50% and 95%). These credible intervals are calculated as follows.
#' Samples from the posterior distribution are drawn and for every sample the simplified fitting step and a prediction is performed. These fits are then used to identify and visualize the specified quantiles.
#' The bootstrap based quantiles can also directly be calculated and displayed via the gotbootstrapQuantiles function.dose-response curves for the specified dose-response models, based on the posterior distributions.
#' For the simplified fit, multivariate normal distributions will be approximated and reduced by one-dimensional normal distributions.
#' For the default case, the Nelder-Mead algorithm is used.
#'
#'
#' @param model_fits an object of class modelFits, i.e. information about fitted models & corresponding model coefficients as well as the posterior distribution that was the basis for the model fitting
#' @param quantiles a vector of quantiles that should be evaluated
#' @param n_samples tbd
#' @param doses tbd
#' @param avg_fit tbd
Expand Down
12 changes: 9 additions & 3 deletions R/modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
#'
#' @description Fits dose-response curves for the specified dose-response models, based on the posterior distributions.
#' For the simplified fit, multivariate normal distributions will be approximated and reduced by one-dimensional normal distributions.
#' For the default case, the Nelder-Mead algorithm is used. Will be further updated and links to publication as well as references will be added.
#'
#' For the default case, the Nelder-Mead algorithm is used.
#' In detail, for both approaches the mean vector and the covariance $\Sigma_{l}^{-1}$ of the mixture posterior distributions and the corresponding posterior weights $\omega_{l}^{*}$ for $l \in {1,...,L}$ is used as basis
#' For the full fit a GLS estimator is used to minimize the following expression for the respective dose-response models $m$
#' $$
#' \hat{\theta}_{m}=argmin_{\theta_{m}} \sum_{i=l}^{L^{*}} \omega_{l}^{*}(\theta_{l_{i}}^{Y}-f(dose_{i},\hat{\theta}_{m}))'\Sigma_{l}^{-1}(\theta_{l_{i}}^{Y}-f(dose_{i},\hat{\theta}_{m}))
#' $$
#' Herefore the function nloptr of the nloptr package is utilized.
#' In the simplified case $L=1$ as the dimension of the posterior is reduced to 1 first.
#' @param models list of model names for which a fit will be performed.
#' @param dose_levels a vector containing the different dosage levels.
#' @param posterior a getPosterior object, containing the (multivariate) posterior distribution per dosage level.
#' @param simple boolean variable, defining whether simplified fit will be applied. Default FALSE.
#'
#' @return model_fits returns a list, containing information about the fitted model coefficients, the prediction per dose group as well as maximum effect and generalized AIC per model.
#' @return model_fits returns a list, containing information about the fitted model coefficients, the prediction per dose group as well as maximum effect and generalized AIC (and corresponding weight) per model.
#'
#' @export
getModelFits <- function (
Expand Down
8 changes: 4 additions & 4 deletions R/s3methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ print.BayesianMCPMod <- function (
cat("Model Significance Frequencies\n")
print(model_success, ...)

if (!is.na(attr(x$BayesianMCP, "ess_avg"))) {
# if (!is.na(attr(x$BayesianMCP, "ess_avg"))) {#Note SB: I have taken this out, as vignettes didn't work

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

}
# }

}

Expand Down
23 changes: 17 additions & 6 deletions man/getContr.Rd

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

12 changes: 10 additions & 2 deletions man/getCritProb.Rd

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

13 changes: 10 additions & 3 deletions man/getModelFits.Rd

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

5 changes: 3 additions & 2 deletions man/performBayesianMCP.Rd

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

6 changes: 3 additions & 3 deletions man/performBayesianMCPMod.Rd

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

14 changes: 9 additions & 5 deletions vignettes/analysis_normal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,16 @@ getBootstrapQuantiles(fit, quantiles = c(0.025,0.5, 0.975), doses = c(0, 2.5,4,
Technical note: The median quantile of the bootstrap based procedure is not necessary similar to the main model fit, as they are derived via different procedures (main fit, i.e. black lines in the plot, show the best fit of a certain model based on minimizing the residuals for the posterior distribution while bootstrap based 50% quantile indicates the median fit of the random sampling and fitting procedure).

# Additional notes
It is also possible to perform the testing and modelling step in combined fashion via the performBayesianMCPMod function.
It is also possible to perform the testing and modelling step in a combined fashion via the performBayesianMCPMod function.

```{r}
#performBayesianMCPMod(
# posterior_list = posterior,
# contr = contr_mat,
# crit_prob_adj = crit_pval)
overall_result<-performBayesianMCPMod(
posterior_list = posterior,
contr = contr_mat,
crit_prob_adj = crit_pval,
simple = FALSE)
overall_result$Mod
```


Expand Down

0 comments on commit 1700b38

Please sign in to comment.