Skip to content

Commit

Permalink
Additional documentations added (and minor update in vignette)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbossert committed Dec 18, 2023
1 parent 20e0baa commit 6440e34
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
13 changes: 13 additions & 0 deletions R/bootstrapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
#' @param doses a vector of doses for which a prediction should be performed
#' @param avg_fit boolean variable, defining whether an average fit (based on generalized AIC weights) should be performed in addition to the individual models. Default TRUE.
#'
#' @examples
#' # example code
#' posterior_list = list(Ctrl=RBesT::mixnorm(comp1 = c(w = 1, m = 0, s = 1), sigma = 2),
#' DG_1=RBesT::mixnorm(comp1 = c(w = 1, m = 3, s = 1.2), sigma = 2),
#' DG_2=RBesT::mixnorm(comp1 = c(w = 1, m = 4, s = 1.5), sigma = 2) ,
#' DG_3=RBesT::mixnorm(comp1 = c(w = 1, m = 6, s = 1.2), sigma = 2) ,
#' DG_4=RBesT::mixnorm(comp1 = c(w = 1, m = 6.5, s = 1.1) ,sigma = 2))
#' models=c("emax","exponential","sigEmax","linear")
#' dose_levels=c(0,1,2,4,8)
#' fit<-getModelFits(models=models, posterior=posterior_list,dose_levels=dose_levels)
#' fit_simple<-getModelFits(models=models, posterior=posterior_list,dose_levels=dose_levels,simple=TRUE)
#' getBootstrapQuantiles(fit, quantiles = c(0.025,0.5, 0.975), doses = c(0, 1,2,3,4,6,8))
#' getBootstrapQuantiles(fit_simple, n_samples=2000, quantiles = c(0.025,0.5, 0.975), doses = c(0, 1,2,3,4,6,8))
#' @return A data frame with entries doses, models, and quantiles
#' @export
getBootstrapQuantiles <- function (
Expand Down
13 changes: 11 additions & 2 deletions R/modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@
#' @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.
#'
#' @examples
#' # example code
#' posterior_list = list(Ctrl=RBesT::mixnorm(comp1 = c(w = 1, m = 0, s = 1), sigma = 2),
#' DG_1=RBesT::mixnorm(comp1 = c(w = 1, m = 3, s = 1.2), sigma = 2),
#' DG_2=RBesT::mixnorm(comp1 = c(w = 1, m = 4, s = 1.5), sigma = 2) ,
#' DG_3=RBesT::mixnorm(comp1 = c(w = 1, m = 6, s = 1.2), sigma = 2) ,
#' DG_4=RBesT::mixnorm(comp1 = c(w = 1, m = 6.5, s = 1.1) ,sigma = 2))
#' models=c("emax","exponential","sigEmax","linear")
#' dose_levels=c(0,1,2,4,8)
#' fit<-getModelFits(models=models, posterior=posterior_list,dose_levels=dose_levels)
#' fit_simple<-getModelFits(models=models, posterior=posterior_list,dose_levels=dose_levels,simple=TRUE)
#' @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
Expand All @@ -23,7 +33,6 @@ getModelFits <- function (
models,
dose_levels,
posterior,
#avg_fit=FALSE, if possible we should add the average fit directly here
simple = FALSE

) {
Expand Down
16 changes: 14 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @description plot function based on the ggplot2 package. Providing visualizations for each model and a average Fit.
#' Black lines show the fitted dose response models and an AIC based average model. Dots indicate the posterior median and vertical lines show corresponding credible intervals (i.e. the variability of the posterior distribution of the respective dose group).
#' To assess the uncertainty of the model fit one can in addition visualize credible bands (yellow/orange shaded areas). The calculation of these bands is performed via the getBootstrapQuantiles function.
#' To assess the uncertainty of the model fit one can in addition visualize credible bands (default coloring as orange shaded areas). The calculation of these bands is performed via the getBootstrapQuantiles function.
#' The default setting is that these credible bands are not calculated.
#' @param x an object of type getModelFits
#' @param gAIC logical value indicating whether gAIC values are shown in the plot. Default TRUE
Expand All @@ -14,7 +14,19 @@
#' @param n_bs_smpl number of bootstrap samples being used. Default set to 1000.
#' @param acc_color color of the credible bands. Default set to "orange"
#' @param ... optional parameter to be passed.
#'
#' @examples
#' # example code
#' posterior_list = list(Ctrl=RBesT::mixnorm(comp1 = c(w = 1, m = 0, s = 1), sigma = 2),
#' DG_1=RBesT::mixnorm(comp1 = c(w = 1, m = 3, s = 1.2), sigma = 2),
#' DG_2=RBesT::mixnorm(comp1 = c(w = 1, m = 4, s = 1.5), sigma = 2) ,
#' DG_3=RBesT::mixnorm(comp1 = c(w = 1, m = 6, s = 1.2), sigma = 2) ,
#' DG_4=RBesT::mixnorm(comp1 = c(w = 1, m = 6.5, s = 1.1) ,sigma = 2))
#' models=c("emax","exponential","sigEmax","linear")
#' dose_levels=c(0,1,2,4,8)
#' fit<-getModelFits(models=models, posterior=posterior_list,dose_levels=dose_levels)
#' fit_simple<-getModelFits(models=models, posterior=posterior_list,dose_levels=dose_levels,simple=TRUE)
#' plot(fit, cr_bands = TRUE)
#' plot(fit_simple, cr_bands = TRUE,alpha_CrB =c(0.05,0.1,0.5))
#' @return plts returns a ggplot2 object
#' @export
plot.modelFits <- function (
Expand Down
2 changes: 1 addition & 1 deletion vignettes/analysis_normal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fit <- getModelFits(

Via the predict function one can also receive estimates for dose levels that were not included in the trial.

It is possible to plot the fitted dose response models and an AIC based average model (black lines). To assess the uncertainty one can in addition visualize credible bands (yellow/orange shaded areas, the default is set to 50% and 95%). These credible bands are calculated as follows.
It is possible to plot the fitted dose response models and an AIC based average model (black lines). To assess the uncertainty one can in addition visualize credible bands (orange shaded areas, the default is set to 50% and 95%). These credible bands 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 be directly calculated and displayed via the getbootstrapQuantiles function.

Expand Down

0 comments on commit 6440e34

Please sign in to comment.