Skip to content
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

Add a new function gs_cp_npe #510

Merged
merged 27 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2ad0f3f
add 1 bib entry
LittleBeannie Dec 11, 2024
d63d6cc
add `gs_cp_npe` fuction
LittleBeannie Dec 11, 2024
dc1aa71
add `gs_cp_ahr` fuction
LittleBeannie Dec 11, 2024
e4f5091
documentations
LittleBeannie Dec 11, 2024
98b9278
add a vignette
LittleBeannie Dec 11, 2024
6805391
add double programming test
LittleBeannie Dec 11, 2024
1ccb283
vignette - change to one-sided design
LittleBeannie Dec 11, 2024
839fb16
test - add test compared with gsDesign
LittleBeannie Dec 11, 2024
c20c882
test - correct tests errors
LittleBeannie Dec 11, 2024
9860aaf
updates of `gs_cp_ahr` and its testing
LittleBeannie Mar 20, 2025
c0cc588
updates of `gs_cp_npe`
LittleBeannie Mar 20, 2025
c3a83d3
delete `gs_cp_ahr` and its tests
LittleBeannie Mar 20, 2025
23a65da
update Rd files
LittleBeannie Mar 20, 2025
be5aac4
delete the double programming `gs_cp`
LittleBeannie Mar 20, 2025
ced1c5c
delete the cp vignette
LittleBeannie Mar 20, 2025
39011f2
update bib file
LittleBeannie Mar 20, 2025
9e51697
update pkgdown.yml
LittleBeannie Mar 20, 2025
0765f4d
add necessary pkg to the examples of `gs_cp_npe`
LittleBeannie Mar 20, 2025
7810a3d
typesetting issue
keaven Mar 23, 2025
9a5d42e
Added to documentation
keaven Mar 24, 2025
24fa751
Updating documentation
keaven Mar 24, 2025
c509aee
Improve equation formatting in gs_cp_npe documentation
keaven Mar 24, 2025
84b4f16
Fixed @param arguments
keaven Mar 24, 2025
991bae2
Update Rd file
LittleBeannie Mar 24, 2025
c6c3b59
update the formula of CP with t_ij = I2/I1
LittleBeannie Mar 24, 2025
67986b3
remove AHR examples and will save them in a vignette
LittleBeannie Mar 24, 2025
809ed32
rename t_ij --> t
LittleBeannie Mar 24, 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 NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export(fixed_design_milestone)
export(fixed_design_rd)
export(fixed_design_rmst)
export(gs_b)
export(gs_cp_npe)
export(gs_create_arm)
export(gs_design_ahr)
export(gs_design_combo)
Expand Down
83 changes: 83 additions & 0 deletions R/gs_cp_npe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the gsDesign2 program.
#
# gsDesign2 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#' Conditional power computation with non-constant effect size
#'
#' @details
#' We assume \eqn{Z_1} and \eqn{Z_2} are the z-values at an interim analysis and later analysis, respectively.
#' We assume further \eqn{Z_1} and \eqn{Z_2} are bivariate normal with standard group sequential assumptions
#' on independent increments where for \eqn{i=1,2}
#' \deqn{E(Z_i) = \theta_i\sqrt{I_i}}
#' \deqn{Var(Z_i) = 1/I_i}
#' \deqn{Cov(Z_1, Z_2) = t \equiv I_1/I_2}
#' where \eqn{\theta_1, \theta_2} are real values and \eqn{0<I_1<I_2}.
#' See https://merck.github.io/gsDesign2/articles/story-npe-background.html for assumption details.
#' Returned value is
#' \deqn{P(Z_2 > b \mid Z_1 = a) = 1 - \Phi\left(\frac{b - \sqrt{t}a - \sqrt{I_2}(\theta_2 - \theta_1\sqrt{t})}{\sqrt{1 - t}}\right)}
#'
#' @param theta A vector of length two, which specifies the natural parameter for treatment effect.
#' The first element of `theta` is the treatment effect of an interim analysis i.
#' The second element of `theta` is the treatment effect of a future analysis j.
#' @param info A vector of two, which specifies the statistical information under the treatment effect `theta`.
#' @param a Interim z-value at analysis i (scalar).
#' @param b Future target z-value at analysis j (scalar).
#' @return A scalar with the conditional power \eqn{P(Z_2>b\mid Z_1=a)}.
#' @export
#'
#' @examples
#' library(gsDesign2)
#' library(dplyr)
#'
#' # Calculate conditional power under arbitrary theta and info
#' # In practice, the value of theta and info commonly comes from a design.
#' # More examples are available at the pkgdown vignettes.
#' gs_cp_npe(theta = c(.1, .2),
#' info = c(15, 35),
#' a = 1.5, b = 1.96)
gs_cp_npe <- function(theta = NULL,
info = NULL,
a = NULL, b = NULL
) {
# ----------------------------------------- #
# input checking #
# ----------------------------------------- #
# check theta
if (is.null(theta)) {
stop("Please provide theta (arbitrary treatment effect) to calculate conditional power.")
} else if (length(theta) == 1) {
theta <- rep(theta, 2)
}

# check info
if (is.null(info)) {
stop("Please provide info (statistical information given the treatment effect theta) to calculate conditional power.")
}

check_info(info)

# ----------------------------------------- #
# calculate conditional power under theta #
# ----------------------------------------- #
t <- info[2] / info[1]
numerator1 <- b - a * sqrt(t)
numerator2 <- theta[2] * sqrt(info[2]) - theta[1] * sqrt(t * info[1])
denominator <- sqrt(1 - t)
conditional_power <- pnorm((numerator1 - numerator2) / denominator, lower.tail = FALSE)

return(conditional_power)
}
5 changes: 5 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ reference:
- gs_info_rd
- gs_power_rd
- gs_design_rd
- title: "Conditional power"
desc: >
Functions for conditional power.
contents:
- gs_cp_npe
- title: "Input definition"
desc: >
Helper functions to define inputs for study design.
Expand Down
48 changes: 48 additions & 0 deletions man/gs_cp_npe.Rd

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

4 changes: 2 additions & 2 deletions vignettes/articles/story-npe-background.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ mt <- tibble::tribble(
"$1$",
"$B_k=\\sqrt{t_k}Z_k$", "$\\sum_{i=1}^{n_k}X_i/\\sqrt N$",
"$t_k\\sqrt{\\mathcal{I}_K}\\
\theta(t_k)=\\mathcal{I}_k\\
\theta(t_k)/\\sqrt{\\mathcal{I}_K}$",
\\theta(t_k)=\\mathcal{I}_k\\
\\theta(t_k)/\\sqrt{\\mathcal{I}_K}$",
"$t_k$"
)
mt %>% kable(escape = FALSE)
Expand Down