Skip to content

99 plot oc #128

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

Merged
merged 43 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
30e1e91
add some new packages, tidy the design doc slight
audreyyeoCH Mar 9, 2025
70aad20
clean
audreyyeoCH Mar 9, 2025
352fa0d
clean
audreyyeoCH Mar 9, 2025
b083af8
[skip style] [skip vbump] Restyle files
github-actions[bot] Mar 9, 2025
ddaf025
empty2
audreyyeoCH Mar 9, 2025
4d4941a
clean DESCRIPTION
audreyyeoCH Mar 9, 2025
43781f8
clean tests
audreyyeoCH Mar 9, 2025
e9392e7
[skip style] [skip vbump] Restyle files
github-actions[bot] Mar 9, 2025
a2050fa
clean
audreyyeoCH Mar 9, 2025
b6e3c28
clean
audreyyeoCH Mar 9, 2025
12826c0
clean
audreyyeoCH Mar 9, 2025
fe38c47
Update R/plotOc.R
audreyyeoCH Mar 10, 2025
0b55077
clean
audreyyeoCH Mar 10, 2025
12427a3
clean
audreyyeoCH Mar 10, 2025
a3d98a5
finally the tests work
audreyyeoCH Mar 13, 2025
371b3c1
Merge branch 'main' into 99_plotOC
audreyyeoCH Mar 13, 2025
e7f7426
[skip style] [skip vbump] Restyle files
github-actions[bot] Mar 13, 2025
b00c5b5
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Mar 13, 2025
1770540
clean
audreyyeoCH Mar 13, 2025
56f6842
footnote
audreyyeoCH Mar 14, 2025
6dd6b89
[skip style] [skip vbump] Restyle files
github-actions[bot] Mar 14, 2025
8dccc19
lintr improvements
audreyyeoCH Mar 14, 2025
605127a
[skip style] [skip vbump] Restyle files
github-actions[bot] Mar 14, 2025
22249a3
clean
audreyyeoCH Mar 14, 2025
2f2781b
clean2
audreyyeoCH Mar 14, 2025
5220eb6
magrittr
audreyyeoCH Mar 14, 2025
1c2fca2
magrittr::%>% added
audreyyeoCH Mar 14, 2025
2905c55
magrittr::%>% added
audreyyeoCH Mar 14, 2025
7493dbc
magrittr::%>% added
audreyyeoCH Mar 14, 2025
4fc4dff
tried another way for pipe
audreyyeoCH Mar 15, 2025
e935d76
clean
audreyyeoCH Mar 15, 2025
84e3a36
empty
audreyyeoCH Mar 15, 2025
6324465
empty
audreyyeoCH Mar 15, 2025
b2db817
check if pipe passes
audreyyeoCH Mar 16, 2025
18e1a85
base pipe instead
audreyyeoCH Mar 16, 2025
0ed2340
clean and pause this PR for a bit, need to work out Design doc
audreyyeoCH Mar 18, 2025
f3958d9
changed package yml theme
audreyyeoCH Apr 1, 2025
9c2eb27
updated .svg using svglite
audreyyeoCH Apr 1, 2025
d05356b
[skip style] [skip vbump] Restyle files
github-actions[bot] Apr 2, 2025
264610b
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Apr 2, 2025
d4d45d9
updated |>
audreyyeoCH Apr 2, 2025
e6ce688
updated tidyr::¨
audreyyeoCH Apr 2, 2025
df86400
clean old folders
audreyyeoCH Apr 3, 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
18 changes: 13 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Authors@R: c(
person("Jiawen", "Zhu", , "[email protected]", role = "aut"),
person("James", "Lymp", role = "aut"),
person("Anastasia", "Teterina", , "[email protected]", role = "aut"),
person("Audrey", "Yeo", , "audrey.yeo@roche.com", role = c("aut")),
person("Audrey", "Yeo", , "audrey.yeo@finc-research.com", role = c("aut")),
person("F. Hoffmann-La Roche Ltd", role = c("cph", "fnd"))
)
Description: The phase1b R package is intended to be used when conducting
Expand All @@ -32,16 +32,24 @@ Suggests:
shinyjs,
shinythemes,
reshape,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
magrittr,
tidyverse,
devtools,
vdiffr
Imports:
ggplot2,
checkmate,
devtools,
lifecycle,
vdiffr,
tools,
tidyr,
dplyr (>= 1.0.0)
dplyr (>= 1.0.0),
tibble,
devtools,
magrittr,
tidyverse,
tools,
vdiffr
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export(plotBeta)
export(plotBetaDiff)
export(plotBounds)
export(plotDecision)
export(plotOc)
export(postprob)
export(postprobBeta)
export(postprobDist)
Expand All @@ -30,11 +31,13 @@ export(qbetadiff)
export(runShinyPhase1b)
export(sumBetadiff)
export(sumTable)
export(vintage_plotOc)
import(checkmate)
importFrom(ggplot2,geom_area)
importFrom(ggplot2,geom_bar)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,ggtitle)
importFrom(graphics,abline)
importFrom(graphics,axis)
importFrom(graphics,barplot)
importFrom(graphics,box)
importFrom(graphics,grid)
importFrom(graphics,hist)
Expand All @@ -43,7 +46,6 @@ importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,polygon)
importFrom(graphics,title)
importFrom(lifecycle,deprecated)
importFrom(stats,acf)
importFrom(stats,binom.test)
Expand Down
2 changes: 1 addition & 1 deletion R/plotBeta.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ plotBeta <- function(alpha, beta) {
#'
#' @example examples/plotBetaDiff.R
#'
#' @importFrom graphics par axis polygon mtext
#' @importFrom ggplot2 geom_line ggtitle geom_area
#' @importFrom stats integrate
#'
#' @export
Expand Down
129 changes: 67 additions & 62 deletions R/plotOc.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#' Helper function for simulation result as input for `plotOc()`
#'
#' Data frame input for bar plot for simulated results of :
#' - `[ocPostprob()]`
#' - `[ocPostprobDist()]`
#' - `[ocPostpred()]`
#' - `[ocPostpredDist()]`
#' - `[ocRctPostprobDist()]`
#' - `[ocRctPredprobDist()]`
#'
#' @inheritParams h_get_oc
#' @typed all_looks : numeric
#' original looks before adjustment by `wiggle = TRUE`, if applied.
#' Different to `all_sizes` which is after the adjustment, if made.
#'
#' @return A data frame or tibble with the following variables :
#' - `decision` : decision `flag` with `TRUE` for Go, `FALSE` for Stop, `NA` for Gray zone.
Expand All @@ -20,73 +13,85 @@
#'
#' @keywords internal
#'
h_get_dataframe_oc <- function(decision, sample_size, all_looks) {
assert_logical(decision)
assert_numeric(sample_size)
assert_numeric(all_looks)
h_get_dataframe_oc <- function(decision, all_sizes, all_looks) {
df <- data.frame(
decision = decision,
sample_size = sample_size,
look = all_looks
all_sizes = all_sizes,
all_looks = all_looks # original looks
)
# summarise into frequency table
df <- df %>%
dplyr::group_by(decision, look) %>%
dplyr::summarise(prop = sum(length(decision)) / nrow(df)) %>%
dplyr::as_tibble()
df <- df |>
dplyr::group_by(decision, all_looks) |>
dplyr::summarise(prop = sum(length(decision)) / nrow(df)) |>
tibble::as_tibble()
# setting levels of factors
all_decision <- c(TRUE, FALSE, NA)
all_looks <- unique(sort(all_looks))
df$decision <- factor(df$decision, levels = all_decision)
df$look <- factor(df$look, levels = all_looks)
df %>%
tidyr::complete(decision, look, fill = list(prop = 0))
decision_levels <- c(TRUE, FALSE, NA)
look_levels <- unique(sort(all_looks))
df$decision <- factor(df$decision, levels = decision_levels)
df$look <- factor(df$all_looks, levels = look_levels)
df <- df |>
tidyr::complete(decision, all_looks, fill = list(prop = 0))
df
}

#' Display the operating characteristics using an oc object
#'
#' Reads results from [ocPredprob()]
#' etc. and displays a bar plot of the operating characteristics

#' Display the operating characteristics results using an `oc` object
#'
#' @typed oc : list
#' returned oc parameters
#' @return nothing, only plots as side effect
#' Plots results from simulated results of :
#' - `[ocPostprob()]`
#' - `[ocPostprobDist()]`
#' - `[ocPostpred()]`
#' - `[ocPostpredDist()]`
#' - `[ocRctPostprobDist()]`
#' - `[ocRctPredprobDist()]`
#'
#' @importFrom graphics barplot title
#' @inheritParams h_get_dataframe_oc
#' @typed wiggle_status : flag
#' from `wiggle` flag in object.
#' @return ggplot object
#'
#' @example examples/plotOc.R
#'
#' @importFrom ggplot2 geom_bar ggtitle
#'
#' @export
#' @keywords graphics
vintage_plotOc <- function(oc) {
if (wiggle == FALSE) {
data <- table(oc$Decision, oc$SampleSize) / oc$params$sim
} else {

}
ggplot(oc, aes(x = name, y = value)) +
geom_bar(stat = "identity") +
ggtitle("Percentage of trials that Go and Stop per look") +
ylabs("Percentage %") +
xlabs("Looks and sample size")

## plot function for oc.predprob or oc.postprob, or the dist versions of them
graphics::barplot(table(oc$Decision, oc$SampleSize) / oc$params$sim, beside = TRUE)

## get the parameter
parDat <- lapply(z$params, deparse)

## get parameters, which are saved in parDat
allParNames <- c(
"p", "p0", "p1",
"delta", "deltaE", "deltaF", "relativeDelta",
"phiL", "phiU", "tL", "tU", "tT", "parE", "parS"
plotOc <- function(decision, all_sizes, all_looks, wiggle_status) {
assert_logical(decision)
assert_numeric(all_sizes)
assert_numeric(all_looks)
assert_flag(wiggle_status)
df <- h_get_dataframe_oc(
decision = decision,
all_sizes = all_sizes,
all_looks = all_looks
)
parInds <- which(names(parDat) %in% allParNames)
barplot <-
ggplot2::ggplot(df, ggplot2::aes(fill = decision, x = look, 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"
) +
ggplot2::theme(title = ggplot2::element_text(size = 13)) +
ggplot2::ylab("percentage") +
ggplot2::theme(axis.text.x = ggplot2::element_text(size = 12)) +
ggplot2::xlab("look (n)") +
ggplot2::scale_fill_manual(
values = c("#009E73", "#FF0046", "lightgrey"),
labels = c("Go", "Stop", "Grey zone")
) +
ggplot2::labs(fill = "Decision")
generic_title <-
"Results from simulation : \nProportion of Go/Stop/Grey zone decisions per interim/final analysis"
wiggle_warning_footnote <- paste("\nNote that sample sizes may differ slightly from the ones labeled")

graphics::title(paste(names(parDat[parInds]), parDat[parInds],
sep = "=", collapse = ", "
))
graphics::title(xlab = paste(dimnames(z$oc)[[2]], signif(z$oc, 3),
sep = " = ", collapse = ", "
))
if (wiggle_status) {
barplot +
ggplot2::ggtitle(label = generic_title) +
ggplot2::labs(caption = wiggle_warning_footnote) +
ggplot2::theme(plot.caption = ggplot2::element_text(hjust = 0, size = 10))
} else {
barplot +
ggplot2::ggtitle(generic_title)
}
}
3 changes: 2 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ url: https://genentech.github.io/phase1b

template:
bootstrap: 5
bootswatch: cerulean
bootswatch: zephyr
includes:
in_header: |
<!-- Global site tag (gtag.js) - Google Analytics -->
Expand All @@ -18,3 +18,4 @@ navbar:
right:
- icon: fa-github
href: https://github.com/genentech/phase1b

Loading