Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyyeoCH committed Sep 16, 2024
2 parents b8cb139 + 65bc5af commit 87f8bbe
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 117 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ coverage.*
.vscode/
.rds
node_modules
vintage_NAMESPACE
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repos:
args: [--style_pkg=styler, --style_fun=tidyverse_style]
- id: roxygenize
additional_dependencies:
- ggplot2
- devtools
- shiny
- checkmate
Expand Down
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ BugReports: https://github.com/genentech/phase1b/issues
Depends:
R (>= 3.6)
Suggests:
scales,
rmarkdown,
bookdown,
knitr,
Expand All @@ -32,6 +33,7 @@ Suggests:
reshape,
testthat (>= 3.0.0)
Imports:
ggplot2,
checkmate,
devtools,
lifecycle
Expand All @@ -42,7 +44,7 @@ Language: en-US
LazyData: true
Roxygen:
list(markdown = TRUE, packages = "roxytypes")
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Config/Needs/documentation:
roxytypes
Remotes:
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export(dbetaMix)
export(dbetabinom)
export(dbetabinomMix)
export(dbetadiff)
export(myPlot)
export(oc2)
export(oc3)
export(ocPostprob)
Expand All @@ -17,7 +16,8 @@ export(ocRctPostprobDist)
export(ocRctPredprobDist)
export(pbetaMix)
export(pbetadiff)
export(plotBetaDist)
export(plotBeta)
export(plotBetaDiff)
export(plotBounds)
export(plotDecision)
export(plotOc)
Expand Down
4 changes: 2 additions & 2 deletions R/dbetabinom.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ dbetabinomMix <- Vectorize(dbetabinomMix, vectorize.args = "x")
#'
#' @keywords internal
h_getBetamixPost <- function(x, n, par, weights) {
assert_numeric(x, lower = 0, upper = n, finite = TRUE)
assert_numeric(n, lower = 0, finite = TRUE)
assert_number(x, lower = 0, upper = n, finite = TRUE)
assert_number(n, lower = 0, finite = TRUE)
assert_matrix(par, min.rows = 1, max.cols = 2, mode = "numeric")
assert_numeric(weights, min.len = 0, len = nrow(par), finite = TRUE)
# We renormalize weights.
Expand Down
70 changes: 33 additions & 37 deletions R/plotBeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,37 @@
#'
#' This function will plot the PDF of a beta distribution
#'
#' @param alpha first parameter of the Beta distribution
#' @param beta second parameter of the Beta distribution
#' @param \dots additional arguments to \code{plot}
#' @return nothing, only produces the plot as side effect
#' @inheritParams dbetabinom
#' @typed alpha : number
#' first parameter of the Beta distribution
#' @typed beta : number
#' second parameter of the Beta distribution
#' @return A beta distribution density plot
#'
#' @importFrom graphics axis
#'
#' @example examples/myPlot.R
#' @example examples/plotBeta.R
#' @export
#' @keywords graphics
myPlot <- function(alpha, beta, ...) {
grid <- seq(from = 0, to = 1, length = 1000)
xticks <- seq(from = 0, to = 1, by = 0.25)

plot(
x = grid,
y = dbeta(grid, alpha, beta),
ylab = "",
xaxt = "n",
yaxt = "n",
type = "l",
xaxs = "i",
yaxs = "i",
...
)

graphics::axis(
side = 1, at = xticks,
labels = paste(xticks * 100, "%", sep = "")
plotBeta <- function(alpha, beta, ...) {
x_support <- seq(from = 0, to = 1, length = 1000)
data <- data.frame(
grid = x_support,
xticks = seq(from = 0, to = 1, by = 0.25),
density = dbeta(x_support, alpha, beta)
)
ggplot2::ggplot(data) +
ggplot2::geom_line(ggplot2::aes(x = grid, y = density)) +
ggplot2::ggtitle(paste("Beta density with alpha =", alpha, "and beta =", beta, "parameters.")) +
ggplot2::xlab("response rate") +
ggplot2::ylab(quote(f(x))) +
ggplot2::theme(axis.ticks.x = ggplot2::element_line(linewidth = 0.5)) +
ggplot2::scale_x_continuous(labels = scales::percent_format())
}




#' Plot Diff Between two Beta distributions
#'
#' This function will plot the PDF of a diffience between two Beta distributions
#' This function will plot the PDF of a difference between two Beta distributions
#'
#' @typed parY : numeric
#' non-negative parameters of the treatment Beta distribution.
Expand All @@ -48,12 +41,13 @@ myPlot <- function(alpha, beta, ...) {
#' @typed cut_B : number
#' a meaningful improvement threshold, the lower boundary of a meaningfully improvement in response rate
#' @typed cut_W : number
#' a poor improvement throshold, the upper boundary of a meaningfully poor improvement in response rate
#' @typed shade :
#' paint the two areas under the curve, default value=1 as "yes". other numbers stands for "no";
#' @typed note : number
#' show values of the colored area, default value=1 as "yes". other numbers stands for "no"
#' @typed \dots additional arguments to \code{plot}
#' a poor improvement threshold, the upper boundary of a meaningfully poor improvement in response rate
#' @typed shade : flag
#' paint the two areas under the curve, default value = TRUE
#' @typed note : flag
#' show values of the colored area, default value = TRUE
#' @typed ... :
#' additional arguments to `ggplot()`
#' @return a ggplot object
#'
#' @example examples/myPlotDiff.R
Expand All @@ -63,12 +57,14 @@ myPlot <- function(alpha, beta, ...) {
#'
#' @export
#' @keywords graphics
plotBetaDist <- function(parY, # parameters of phase Ib trial;
plotBetaDiff <- function(parY, # parameters of phase Ib trial;
parX, # parameters of HC;
cut_B = 0.20, # a meaningful improvement threshold;
cut_W = 0.1, # a poor improvement threshold;
shade = 1, # paint the two areas under the curve, default: yes. other numbers stands for "no";
note = 1, # show values of the colored area, default: yes. other numbers stands for "no";
shade = TRUE, # paint the two areas under the curve,
# default: yes. other numbers stands for "no";
note = TRUE, # show values of the colored area,
# default: yes. other numbers stands for "no";
...) {
if (note == 1) {
graphics::par(mar = c(5, 15, 1, 15) + .1)
Expand Down
2 changes: 0 additions & 2 deletions examples/myPlot.R

This file was deleted.

9 changes: 8 additions & 1 deletion examples/myPlotDiff.R
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
myPlotDiff(c(5, 10), c(2, 5), 0.2, 0.05, 1, 0)
myPlotDiff(
parY = c(5, 10),
parX = c(2, 5),
cut_B = 0.2, # a meaningful improvement threshold
cut_W = 0.05, # a poor improvement threshold
shade = 1, # paint the two areas under the curve, default: yes. other numbers stands for "no";
note = 0
) # show values of the colored area, default: yes. other numbers stands for "no";
2 changes: 2 additions & 0 deletions examples/plotBeta.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plotBeta(alpha = 4, beta = 5)
plotBeta(alpha = 1, beta = 1)
26 changes: 0 additions & 26 deletions man/myPlot.Rd

This file was deleted.

121 changes: 121 additions & 0 deletions man/ocPredprob.Rd

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

24 changes: 24 additions & 0 deletions man/plotBeta.Rd

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

Loading

0 comments on commit 87f8bbe

Please sign in to comment.