Skip to content

102 plot decision #136

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

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
e9033c0
clean
audreyyeoCH May 8, 2025
68d43b3
clean
audreyyeoCH May 12, 2025
85ddbe8
[skip style] [skip vbump] Restyle files
github-actions[bot] May 12, 2025
4a28e60
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 12, 2025
c743510
101 sum table (#133)
audreyyeoCH May 7, 2025
622b583
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 12, 2025
3e4f0a9
clean
audreyyeoCH May 13, 2025
74619fc
101 sum table (#133)
audreyyeoCH May 7, 2025
7d6592f
clean
audreyyeoCH May 13, 2025
74b3682
annotation done
audreyyeoCH May 13, 2025
a31aafc
clean up documentation
audreyyeoCH May 13, 2025
9ef9e90
Merge branch 'main' into 102_plotDecision
audreyyeoCH May 13, 2025
594fe54
[skip style] [skip vbump] Restyle files
github-actions[bot] May 13, 2025
4ba090e
clean up
audreyyeoCH May 13, 2025
eed5b3f
clean
audreyyeoCH May 13, 2025
6d6963e
[skip style] [skip vbump] Restyle files
github-actions[bot] May 13, 2025
50cf080
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 13, 2025
0548ad9
git auto checks
audreyyeoCH May 13, 2025
a1042f7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 13, 2025
8759336
empty trigger
audreyyeoCH May 14, 2025
4808c88
see if this runs well
audreyyeoCH May 14, 2025
c4ef49b
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 14, 2025
c25bac8
carpe diem
audreyyeoCH May 14, 2025
890862e
[skip style] [skip vbump] Restyle files
github-actions[bot] May 14, 2025
76b1c49
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 14, 2025
5d2cae1
fix collate DESC
audreyyeoCH May 15, 2025
3fc44c7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 15, 2025
227d975
test that buggy
audreyyeoCH May 15, 2025
1cb5fa1
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 15, 2025
5fee0de
changed test file location
audreyyeoCH May 15, 2025
3322ebd
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 15, 2025
3158b8f
small stuff
audreyyeoCH May 15, 2025
a0d820c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 15, 2025
34859c0
i re-installed to see if it makes a diff
audreyyeoCH May 15, 2025
d322ab7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 15, 2025
091c5d1
small caps fixes
audreyyeoCH May 15, 2025
7b6d1f5
clean
audreyyeoCH May 15, 2025
2dec923
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 15, 2025
bddfe59
trying this solution for the format of sumBetaDiff
audreyyeoCH May 16, 2025
7691bfc
[skip style] [skip vbump] Restyle files
github-actions[bot] May 16, 2025
bcd6ae7
carpe diem
audreyyeoCH May 16, 2025
4e07761
clean
audreyyeoCH May 16, 2025
4945dc3
notice a couple of errors and fixed it
audreyyeoCH May 17, 2025
3978c3e
[skip style] [skip vbump] Restyle files
github-actions[bot] May 17, 2025
8255831
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 17, 2025
3cc7c8f
clean
audreyyeoCH May 19, 2025
afe005b
sumTable tag
audreyyeoCH May 20, 2025
0489214
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 20, 2025
efff2ef
clean
audreyyeoCH May 20, 2025
9aad254
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 20, 2025
961e66c
clean
audreyyeoCH May 20, 2025
af169c4
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 20, 2025
6beaf13
try to make file names consistent for `sumBetaDiff`
danielinteractive May 21, 2025
39b2f3f
[skip style] [skip vbump] Restyle files
github-actions[bot] May 21, 2025
ce4a2b7
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 21, 2025
419a144
rename again using `git mv` command
danielinteractive May 21, 2025
0211919
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] May 21, 2025
810789c
clean
audreyyeoCH Jun 11, 2025
98120eb
clean
audreyyeoCH Jun 11, 2025
4dd2713
clean
audreyyeoCH Jun 11, 2025
8424ac8
clean
audreyyeoCH Jun 11, 2025
f0d9a92
empty
audreyyeoCH Jun 11, 2025
64db8fa
packagedown labels
audreyyeoCH Jun 11, 2025
6a8e722
undo check.yml edits
audreyyeoCH Jun 11, 2025
71dcaad
empty
audreyyeoCH Jun 11, 2025
2d98b58
undo check yml changes
audreyyeoCH Jun 11, 2025
81f8d33
empty
audreyyeoCH Jun 12, 2025
de80695
remove devtools command
audreyyeoCH Jun 13, 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
9 changes: 5 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ export(runShinyPhase1b)
export(sumBetaDiff)
export(sumTable)
import(checkmate)
importFrom(ggplot2,annotate)
importFrom(ggplot2,geom_area)
importFrom(ggplot2,geom_bar)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,theme_light)
importFrom(ggplot2,xlab)
importFrom(ggplot2,ylab)
importFrom(graphics,abline)
importFrom(graphics,axis)
importFrom(graphics,box)
importFrom(graphics,grid)
importFrom(graphics,hist)
importFrom(graphics,lines)
importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,polygon)
importFrom(lifecycle,deprecated)
Expand All @@ -56,3 +56,4 @@ importFrom(stats,optimize)
importFrom(stats,pbeta)
importFrom(stats,rbinom)
importFrom(stats,uniroot)
importFrom(tibble,remove_rownames)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions R/plotBeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ plotBetaDiff <- function(parX, # parameters of control or SOC
temp <- sumBetaDiff(
parX = parX,
parY = parY,
go_cut = go_cut,
stop_cut = stop_cut
go_cut = go_cut, # in response rate
stop_cut = stop_cut # in response rate
)

go_label <- paste("P(Go) is", round(temp$go * 100, digits = 2), "%")
Expand Down
186 changes: 64 additions & 122 deletions R/plotDecision.R
Original file line number Diff line number Diff line change
@@ -1,137 +1,79 @@
#' Plot a summary plot corresponding to the sumTable output
#'
#' This function will return a plot showing a curve of the prob of a meaningful improvement over estunated diff
#' and a curve of the prob of a poor improvement over estunated diff
#' @param data the output object of \code{\link{sumTable}}
#' @param Pos_cut a cut off for the prob of a meaningful improvement
#' @param Neg_cut a cut off for the prob of a poor improvement
#' @return the \code{data} item which was imputed to the function
#' This function will return a plot showing a curve of the prob of a meaningful improvement over estimated diff
#' and a curve of the prob of a poor improvement over estimated diff
#'
#' @importFrom graphics lines abline polygon plot par grid mtext box axis
#' @typed data : data.frame
#' sourced [`data.frame`] from [(sumTable)]
#' @typed efficacious_prob : number
#' a cut off for the probability of a meaningful improvement
#' @typed futile_prob : number
#' a cut off for the probability of a poor improvement
#' @return [`ggplot`] object
#'
#' @importFrom ggplot2 geom_line geom_area ggtitle theme_light annotate xlab ylab
#' @importFrom tibble remove_rownames
#'
#' @example examples/plotDecision.R
#' @export
#' @keywords graphics
plotDecision <- function(data, Pos_cut, Neg_cut) {
xticks <- seq(from = -50, to = 100, by = 10)

x <- as.numeric(data[1, ]) # number of response;

x.mode <- as.numeric(data[3, ]) # the response diff mode

y <- as.numeric(data[6, ]) # The Prob of a meaningful improvement

z <- as.numeric(data[7, ]) # The Prob of a not meaningful improvement

# Look up decision area;
ShadeData <- t(data)

colnames(ShadeData)

# Green area;
G_area <- ShadeData[ShadeData[, "prob.go [%]"] > Pos_cut, ]
# Red ares;
R_area <- ShadeData[ShadeData[, "prob.nogo [%]"] > Neg_cut, ]

graphics::par(mar = c(5, 4, 4, 1) + .1)


graphics::plot(x.mode, y,
type = "n", xlim = range(x.mode), bty = "n", ylab = "Probability (%)", xaxt = "n", xaxs = "i", yaxs = "i",
xlab = expression(paste("Estimated diff.", sep = "")), ylim = c(0, 100), panel.first = grid()
plotDecision <- function(data, efficacious_prob, futile_prob) {
assert_data_frame(data, any.missing = FALSE)
assert_number(efficacious_prob, finite = TRUE)
assert_number(futile_prob, finite = TRUE)

data <- data.frame(t(data))

data <- tibble::remove_rownames(data)

colnames(data) <- c(
"responders",
"obs",
"mode",
"ci_lower",
"ci_upper",
"prob_go",
"prob_stop"
)

go_shade <- data[data$prob_go > efficacious_prob, ]

stop_shade <- data[data$prob_stop > futile_prob, ]

# find the interaction;


# Green area;
aboveG <- ShadeData[, "prob.go [%]"] > Pos_cut
# Red ares;
aboveR <- ShadeData[, "prob.nogo [%]"] > Neg_cut

# Points always intersect when above=TRUE, then FALSE or reverse
intersect.pointsG <- which(diff(aboveG) != 0)
intersect.pointsR <- which(diff(aboveR) != 0)
# Find the slopes for each line segment.
x1.slopesG <- (ShadeData[intersect.pointsG + 1, "prob.go [%]"] - ShadeData[intersect.pointsG, "prob.go [%]"]) /
(ShadeData[intersect.pointsG + 1, "mode [%]"] - ShadeData[intersect.pointsG, "mode [%]"])
x1.slopesR <- (ShadeData[intersect.pointsR + 1, "prob.nogo [%]"] - ShadeData[intersect.pointsR, "prob.nogo [%]"]) /
(ShadeData[intersect.pointsR + 1, "mode [%]"] - ShadeData[intersect.pointsR, "mode [%]"])

x2.slopes <- 0
# Find the intersection for each segment.
x.pointsG <- ShadeData[intersect.pointsG, "mode [%]"] +
((Pos_cut - ShadeData[intersect.pointsG, "prob.go [%]"]) / (x1.slopesG))
y.pointsG <- Pos_cut

x.pointsR <- ShadeData[intersect.pointsR, "mode [%]"] +
((Neg_cut - ShadeData[intersect.pointsR, "prob.nogo [%]"]) / (x1.slopesR))
y.pointsR <- Neg_cut


graphics::polygon(c(R_area[, "mode [%]"], x.pointsR, x.pointsR, rev(R_area[, "mode [%]"])),
c(rep(0, dim(R_area)[1] + 1), y.pointsR, rev(R_area[, "prob.nogo [%]"])),
col = "red"
)

graphics::mtext(
paste(
"Est. Diff=",
round(x.pointsR),
"%, Prob.nogo=",
round(y.pointsR),
"%",
sep = ""
),
side = 3,
line = 2
annotation_go <- paste0(
"Probability of Go is ", efficacious_prob, "% when difference is at least ",
min(data$mode[data$prob_go > efficacious_prob]), "%"
)

graphics::polygon(
c(
x.pointsG, G_area[, "mode [%]"],
rev(G_area[, "mode [%]"]), x.pointsG
),
c(
rep(0, dim(G_area)[1] + 1),
rev(G_area[, "prob.go [%]"]), y.pointsG
),
col = "green"
) # meaningful part;

graphics::mtext(
paste(
"Est. Diff=",
round(x.pointsG),
"%,Prob. go=",
round(y.pointsG),
"%",
sep = ""
),
side = 3,
line = 1
annotation_stop <- paste0(
"Probability of Stop is ", futile_prob, "% when difference is at most ",
max(data$mode[data$prob_stop > futile_prob]), "%"
)

graphics::lines(x.mode, y, col = "green", lwd = 3, type = "l") # Plot PDF of beta(R,NR);

graphics::lines(x.mode, z, col = "red", lwd = 3, type = "l")



if (Pos_cut == Neg_cut) {
graphics::abline(h = Pos_cut, col = "black", lwd = 2)
}

graphics::box()

LablePoint2 <- unique(sort(c(
ceiling(min(x.mode) * 10) / 10,
xticks, floor(max(x.mode) * 10) / 10
))) ## Can be modified

graphics::axis(1, at = LablePoint2, labels = paste(LablePoint2, "%", sep = ""), las = 1, lwd = 2, cex.axis = 1)

data
ggplot2::ggplot(data) +
ggplot2::geom_line(
ggplot2::aes(x = mode, y = prob_go),
linewidth = 1.5, colour = "#009E73"
) +
ggplot2::theme_light() +
ggplot2::scale_x_continuous(breaks = seq(from = 0, to = round(max(data$mode), digits = 1), by = 5)) +
ggplot2::geom_area(
data = go_shade,
mapping = ggplot2::aes(x = mode, y = prob_go),
fill = "#009E73"
) +
ggplot2::geom_line(
data = data,
mapping = ggplot2::aes(x = mode, y = prob_stop),
linewidth = 1.5, colour = "#FF0046"
) +
ggplot2::geom_area(
data = stop_shade,
mapping = ggplot2::aes(x = mode, y = prob_stop),
fill = "#FF0046"
) +
ggplot2::ggtitle("Probability of Difference and respective Go and Stop probabilities.") +
ggplot2::xlab("Difference between treatment in Response Rate (%)") +
ggplot2::ylab("Probability (%)") +
ggplot2::annotate("text", x = mean(data$mode), y = 90, label = annotation_go) +
ggplot2::annotate("text", x = mean(data$mode), y = 85, label = annotation_stop)
}
4 changes: 2 additions & 2 deletions R/plotOc.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ h_get_dataframe_oc <- function(decision, all_sizes, all_looks) {
#' @inheritParams h_get_dataframe_oc
#' @typed wiggle_status : flag
#' from `wiggle` flag in object.
#' @return ggplot object
#' @return [`ggplot`] object
#'
#' @example examples/plotOc.R
#'
Expand All @@ -67,7 +67,7 @@ plotOc <- function(decision, all_sizes, all_looks, wiggle_status) {
all_looks = all_looks
)
barplot <-
ggplot2::ggplot(df, ggplot2::aes(fill = decision, x = look, y = prop)) +
ggplot2::ggplot(df, ggplot2::aes(fill = decision, x = all_looks, y = prop)) +
ggplot2::geom_bar(position = "dodge", stat = "identity") +
ggplot2::ggtitle(
"Results from simulation : \nProportion of Go/Stop/Grey zone decisions per interim/final analysis"
Expand Down
3 changes: 2 additions & 1 deletion R/sumbetadiff.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#'
#' @importFrom stats optimize integrate
#'
#' @example examples/sumbetadiff.R
#' @example examples/sumBetaDiff.R
#' @export
sumBetaDiff <- function(parX, # Treatment group's parameters
parY, # Control group's parameters
Expand Down Expand Up @@ -49,6 +49,7 @@ sumBetaDiff <- function(parX, # Treatment group's parameters
parY = parY,
parX = parX
)

# Prob for Go:
prob_go <- stats::integrate(
f = dbetadiff,
Expand Down
Loading
Loading