Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
4f8d4c8
Merge remote-tracking branch 'origin/HEAD'
audreyyeoCH May 17, 2024
dff2ff6
delete helpers
audreyyeoCH May 21, 2024
37561fc
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 21, 2024
ab9ba06
clean
audreyyeoCH May 24, 2024
ab51030
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 24, 2024
008502d
clean
audreyyeoCH May 24, 2024
3bc1cf1
"clean+"
audreyyeoCH May 24, 2024
34a2313
empty
audreyyeoCH May 24, 2024
0cd95a7
examples and test there
audreyyeoCH May 26, 2024
51db59a
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 26, 2024
df9a7ca
clean
audreyyeoCH May 26, 2024
bc6dac2
Mergen"
audreyyeoCH May 26, 2024
bd327cc
NAMESPACE stuff
audreyyeoCH May 26, 2024
e25e4fd
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 26, 2024
c6ec5cc
empty
audreyyeoCH May 27, 2024
fe22df6
add rmarkdown to DESCRIPTIOPM
audreyyeoCH May 27, 2024
f1a2978
Merge branch 'main' into 94_helpers.R
audreyyeoCH May 27, 2024
95a6080
clean
audreyyeoCH May 27, 2024
cc665fc
Merge branch 'main' into 92_boundsPostprob
audreyyeoCH May 27, 2024
670558d
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 27, 2024
4f3c785
Merge remote-tracking branch 'origin/HEAD'
audreyyeoCH May 27, 2024
947e1cb
Merge branch 'main' of github.com:Genentech/phase1b
audreyyeoCH May 28, 2024
9d8a2b3
Merge branch 'main' into 92_boundsPostprob
audreyyeoCH May 31, 2024
42595d7
Merge branch 'main' of github.com:Genentech/phase1b
audreyyeoCH Jun 2, 2024
62611fa
Merge branch 'main' into 94_helpers.R
audreyyeoCH Jun 2, 2024
a29fd0f
should pass CMD checks
audreyyeoCH Jun 2, 2024
b9c7abd
Merge branch '94_helpers.R'
audreyyeoCH Jun 3, 2024
fe3f37f
see if CMD checks pass now
audreyyeoCH Jun 3, 2024
155571b
Merge branch '92_boundsPostprob'
audreyyeoCH Jun 6, 2024
d4759ef
clean
audreyyeoCH Jun 11, 2024
188027d
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Jun 11, 2024
b8cb139
Merge branch 'main' into 109_myPlotDiff
audreyyeoCH Jun 26, 2024
87f8bbe
clean
audreyyeoCH Sep 16, 2024
40b490e
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 16, 2024
0747fbb
Merge branch 'main' into 109_myPlotDiff
audreyyeoCH Sep 16, 2024
97b0685
just some first drafts
audreyyeoCH Sep 22, 2024
be2e55b
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 22, 2024
7e75e68
exame file for plotBetaDiff.R
audreyyeoCH Sep 22, 2024
e1094e1
Merge branch '109_myPlotDiff' of github.com:Genentech/phase1b into 10…
audreyyeoCH Sep 22, 2024
ec5abb8
empty
audreyyeoCH May 27, 2024
2757aab
should pass CMD checks
audreyyeoCH Jun 2, 2024
93f463a
clean
audreyyeoCH Sep 22, 2024
27cfdc9
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 22, 2024
b569a7a
clean
audreyyeoCH Sep 23, 2024
db9412d
clean
audreyyeoCH May 24, 2024
6484d12
clean
audreyyeoCH Sep 23, 2024
9694d1b
Merge branch 'main' into 109_myPlotDiff
audreyyeoCH Jan 2, 2025
21f0ee4
clean
audreyyeoCH Jan 2, 2025
f922d46
clean
audreyyeoCH Jan 2, 2025
01b8185
plot and examples added
audreyyeoCH Jan 3, 2025
c475a98
for PR review before .svg files for test
audreyyeoCH Jan 3, 2025
3a65c36
[skip style] [skip vbump] Restyle files
github-actions[bot] Jan 6, 2025
e38b84f
clean
audreyyeoCH Jan 9, 2025
65f41fb
addressing R CMD check error
audreyyeoCH Jan 13, 2025
4b66fc5
addressing R CMD check error on plotBetaDiff
audreyyeoCH Jan 13, 2025
53b626b
clean2
audreyyeoCH Jan 21, 2025
8c9926a
clean
audreyyeoCH Jan 27, 2025
4474235
test passes
audreyyeoCH Jan 28, 2025
d1d529e
Merge branch 'main' into 109_myPlotDiff
audreyyeoCH Jan 28, 2025
f91f170
fix linter issues
audreyyeoCH Jan 28, 2025
2f08019
clean intro
audreyyeoCH Jan 28, 2025
96b0326
aes error
audreyyeoCH Jan 28, 2025
34bb3c9
clean2
audreyyeoCH Feb 1, 2025
b3300b6
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Feb 1, 2025
685a236
clean
audreyyeoCH Feb 1, 2025
1065782
small cases arguments
audreyyeoCH Feb 1, 2025
08ef109
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Feb 1, 2025
e04fcb2
fix rcmd errors on intro
audreyyeoCH Feb 1, 2025
36e4fb9
clean
audreyyeoCH Feb 2, 2025
38d126d
swapsies X and Y to follow dbetadiff
audreyyeoCH Feb 2, 2025
cbbaf89
some c rmd fixes
audreyyeoCH Feb 2, 2025
9609ffb
ggplot2::aes prefix added
audreyyeoCH Feb 7, 2025
5a38eb5
vdiffr added
audreyyeoCH Feb 8, 2025
214c176
Empty-Commit
audreyyeoCH Feb 8, 2025
dba0d4f
cut_W, cut_B -> update
audreyyeoCH Feb 8, 2025
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
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
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ Imports:
ggplot2,
checkmate,
devtools,
lifecycle
lifecycle,
vdiffr,
tools,
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion 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(myPlotDiff)
export(oc2)
export(oc3)
export(ocPostprob)
Expand All @@ -18,6 +17,7 @@ export(ocRctPredprobDist)
export(pbetaMix)
export(pbetadiff)
export(plotBeta)
export(plotBetaDiff)
export(plotBounds)
export(plotDecision)
export(plotOc)
Expand Down
197 changes: 77 additions & 120 deletions R/plotBeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#' first parameter of the Beta distribution
#' @typed beta : number
#' second parameter of the Beta distribution
#'
#' @return A beta distribution density plot
#'
#' @importFrom graphics axis
Expand All @@ -15,6 +14,8 @@
#' @export
#' @keywords graphics
plotBeta <- function(alpha, beta) {
assert_number(alpha, finite = TRUE)
assert_number(beta, finite = TRUE)
x_support <- seq(from = 0, to = 1, length = 1000)
data <- data.frame(
grid = x_support,
Expand All @@ -30,141 +31,97 @@ plotBeta <- function(alpha, beta) {
ggplot2::scale_x_continuous(labels = scales::percent_format())
}

#' Plot Diff Between two Beta distributions
#' Plot difference Between two Beta distributions
#'
#' This function will plot the PDF of a difference between two Beta distributions
#'
#' @param parY non-negative parameters of the treatment Beta distribution.
#' @param parX non-negative parameters of the historical control Beta distribution
#' @param cut_B a meaningful improvement threshold
#' @param cut_W a poor improvement throshold
#' @param shade paint the two areas under the curve, default value=1 as "yes". other numbers stands for "no";
#' @param note show values of the colored area, default value=1 as "yes". other numbers stands for "no"
#' @param \dots additional arguments to \code{plot}
#' @return nothing, only produces the plot as side effect
#' @typed parX : numeric
#' non-negative parameters of the control Beta distribution
#' @typed parY : numeric
#' non-negative parameters of the treatment Beta distribution.
#' @typed go_cut : number
#' a meaningful improvement threshold, the lower boundary of a meaningfully improvement in response rate
#' @typed stop_cut : number
#' 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
#' @return a ggplot object
#'
#' @example examples/myPlotDiff.R
#' @example examples/plotBetaDiff.R
#'
#' @importFrom graphics par axis polygon mtext
#' @importFrom stats integrate
#'
#' @export
#' @keywords graphics
myPlotDiff <- 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";
...) {
if (note == 1) {
graphics::par(mar = c(5, 15, 1, 15) + .1)
} else {
graphics::par(mar = c(5, 5, 1, 5) + .1)
}
grid <- seq(from = -0.5, to = 0.75, length = 1000)
xticks <- seq(from = -1, to = 1, by = 0.25)

plotBetaDiff <- function(parX, # parameters of control or SOC
parY, # parameters of experimental arm
go_cut = 0.20, # a meaningful improvement threshold
stop_cut = 0.1, # a poor improvement threshold
shade = TRUE, # paint the two areas under the curve
note = TRUE) { # show values of the colored area
assert_numeric(parX, lower = 0, finite = TRUE, any.missing = FALSE)
assert_numeric(parY, lower = 0, finite = TRUE, any.missing = FALSE)
assert_number(go_cut, finite = TRUE)
assert_number(stop_cut, finite = TRUE)
assert_flag(shade)
assert_flag(note)


graphics::plot(
x = grid,
y = dbetadiff(grid, parY = parY, parX = parX),
ylab = "",
xaxt = "n",
yaxt = "n",
type = "l",
xaxs = "i",
yaxs = "i",
...
diff <- seq(from = -1, to = 1, length = 1000)
data <- data.frame(
grid = diff,
density = dbetadiff(z = diff, parY = parY, parX = parX)
)
data$stop <- ifelse(diff > -1 & diff < stop_cut, TRUE, FALSE)
data$go <- ifelse(diff > go_cut & diff < 1, TRUE, FALSE)

graphics::axis(
side = 1, at = xticks,
labels =
paste(ifelse(xticks >= 0, "+", ""),
xticks * 100, "%",
sep = ""
)
go_auc <- integrate(
f = dbetadiff,
parX = parX,
parY = parY,
lower = go_cut, # Calculate probability of go, if difference was at least `go_cut`.
upper = 1
)
stop_auc <- integrate(
f = dbetadiff,
parX = parX,
parY = parY,
lower = -1,
upper = stop_cut # Calculate probability of stop, if difference was at most `stop_cut`.
)

## now color the go / stop prob areas

if (shade == 1) {
## first stop:
stopGrid <- grid[grid <= cut_W]
nStop <- length(stopGrid)

graphics::polygon(
x =
c(
stopGrid,
rev(stopGrid)
),
y =
c(
rep(0, nStop),
dbetadiff(rev(stopGrid), parY = parY, parX = parX)
),
col = "red"
)

A_value <- stats::integrate(
f = dbetadiff,
parY = parY,
parX = parX,
lower = -1,
upper = cut_W
)
if (note == 1) {
graphics::mtext(
paste("Prob(diff< ", round(cut_W * 100), "%)=",
sprintf("%1.2f%%", 100 * as.numeric(A_value$value)),
sep = ""
),
side = 2, line = 1, las = 1, cex = 1
)
}

## then go:
goGrid <- grid[grid >= cut_B]
nGo <- length(goGrid)

graphics::polygon(
x =
c(
goGrid,
rev(goGrid)
),
y =
c(
rep(0, nGo),
dbetadiff(rev(goGrid), parY = parY, parX = parX)
),
col = "green"
)
go_label <- paste("P(Go) is", round(go_auc$value * 100, digits = 2), "%")
stop_label <- paste("P(Stop) is", round(stop_auc$value * 100, digits = 2), "%")
plot_title <- paste("According to Beta difference density", go_label, "and", stop_label)

B_value <- stats::integrate(
f = dbetadiff,
parY = parY,
parX = parX,
lower = cut_B,
upper = 1
)

if (note == 1) {
graphics::mtext(
paste(
sprintf("%1.2f%%", 100 * as.numeric(B_value$value)),
"=Prob(diff> ",
round(cut_B * 100), "%)",
sep = ""
),
side = 4,
line = 1,
las = 1,
cex = 1
)
}
pbetadiff_plot <- if (shade) {
ggplot2::ggplot(data = data, mapping = ggplot2::aes(x = grid, y = density)) +
ggplot2::geom_line(colour = "#888888") +
ggplot2::geom_area(
data = data[data$grid < stop_cut, ], fill = "#FF0046",
mapping = ggplot2::aes(x = ifelse(grid < 0.2 & grid < 0.5, grid, 0))
) +
ggplot2::geom_area(
data = data[data$grid > go_cut, ], fill = "#009E73",
mapping = ggplot2::aes(x = ifelse(grid > 0.3, grid, 0))
) +
ggplot2::xlab("Difference between treatment") +
ggplot2::ylab(quote(f(x))) +
ggplot2::ggtitle(plot_title)
} else {
pbetadiff_plot <- ggplot2::ggplot(data = data) +
ggplot2::geom_line(aes(x = grid, y = density, colour = "#888888")) +
xlab("Difference between treatment") +
ggplot2::ylab(quote(f(x))) +
ggplot2::ggtitle(plot_title)
}
if (note) {
pbetadiff_plot <- pbetadiff_plot +
ggplot2::annotate("text", x = -0.5, y = 3.75, size = 5, label = stop_label, colour = "#FF0046") +
ggplot2::annotate("text", x = -0.5, y = 3.25, size = 5, label = go_label, colour = "#009E73")
}
pbetadiff_plot
}
8 changes: 0 additions & 8 deletions examples/myPlotDiff.R

This file was deleted.

22 changes: 22 additions & 0 deletions examples/plotBetaDiff.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# The beta distribution and acceptable bounds for
# a meaningful improvement of 0.30 and worsening of 0.1
parX <- c(1, 52) # prior parameters of control or SOC
parY <- c(5.5, 20.5) # prior parameters of experimental arm
plotBetaDiff(
parX = parX,
parY = parY,
go_cut = 0.3,
stop_cut = 0.1, # below a difference of 10%, is an unsuccessful trial
shade = TRUE,
note = TRUE
)

# a larger Go_cut with uniform prior
plotBetaDiff(
parX = c(1, 1), # prior parameters for experimental arm
parY = c(1, 1), # prior parameters for control or SOC arm
go_cut = 0.3,
stop_cut = 0.1, # below a difference of 10%, is an unsuccessful trial
shade = TRUE,
note = TRUE
)
4 changes: 4 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ gelman
Gelman
generalizable
geq
ggplot
grayzone
grey
Gsponer
Expand Down Expand Up @@ -201,6 +202,8 @@ renewcommand
reproducibility
responder
responders
roxygen
Roxygen
Sabanes
sabanes
Sabanés
Expand Down Expand Up @@ -243,6 +246,7 @@ USUBJID
VAD
vanillaBayes
vanillaPP
vbump
Vehtari
WeightedBayes
weightedBetaPrior
Expand Down
40 changes: 0 additions & 40 deletions man/myPlotDiff.Rd

This file was deleted.

Loading
Loading