Skip to content

Commit

Permalink
Merge pull request #201 from jdblischak/function-factory
Browse files Browse the repository at this point in the history
Use function factory pattern to pass cutting functions to `sim_gs_n()`
  • Loading branch information
nanxstats authored Feb 23, 2024
2 parents f9d7581 + b302c3e commit caadb3e
Show file tree
Hide file tree
Showing 43 changed files with 540 additions and 171 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: simtrial
Type: Package
Title: Clinical Trial Simulation
Version: 0.3.2.4
Version: 0.3.2.7
Authors@R: c(
person("Keaven", "Anderson", email = "[email protected]", role = c("aut")),
person("Yilong", "Zhang", email = "[email protected]", role = c("aut")),
Expand Down Expand Up @@ -44,7 +44,6 @@ Imports:
future,
methods,
mvtnorm,
rlang,
stats,
survival,
utils
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

simtrial: Clinical Trial Simulation
Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. All rights reserved.
Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

simtrial Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. All rights reserved.
simtrial Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates. All rights reserved.
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(counting_process)
export(create_cutting)
export(cut_data_by_date)
export(cut_data_by_event)
export(early_zero)
Expand Down
2 changes: 1 addition & 1 deletion R/counting_process.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/cut_data_by_date.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/cut_data_by_event.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/early_zero_weight.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/ex1_delayed_effect.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/ex2_delayed_effect.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/ex3_cure_with_ph.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/ex4_belly.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/ex5_widening.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/ex6_crossing.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/fh_weight.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/fit_pwexp.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/get_analysis_date.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/get_cut_date_by_event.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/global.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/input_checking.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
41 changes: 20 additions & 21 deletions R/maxcombo.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand All @@ -18,38 +18,37 @@

#' Maxcombo test
#'
#' WARNING: This experimental function is a work-in-progress. The function
#' arguments will change as we add additional features.
#'
#' @param data a tte dataset
#' @param test1 maxcombo test1
#' @param test2 maxcombo test2
#' @param ... additional tests
#' @param rho Numeric vector passed to \code{\link{fh_weight}}. Must be greater
#' than or equal to zero. Must be the same length as \code{gamma}.
#' @param gamma Numeric vector passed to \code{\link{fh_weight}}. Must be
#' greater than or equal to zero. Must be the same length as \code{rho}.
#'
#' @return pvalues
#' @export
#'
#' @seealso \code{\link{fh_weight}}
#'
#' @examples
#' sim_pw_surv(n = 200) |>
#' cut_data_by_event(150) |>
#' maxcombo(test1 = wlr(data, rho = 0, gamma = 0) |> quote(),
#' test2 = wlr(data, rho = 0, gamma = 0.5) |> quote())
maxcombo <- function(data, test1, test2, ...){
all_args <- match.call(expand.dots = FALSE)
args <- all_args[-1] # Exclude the first element (function name)

n_test <- length(args) - 1
rho_vector <- NULL
gamma_vector <- NULL

for (i in 1:n_test) {
test_i <- get(paste0("test", i))
rho_vector <- c(rho_vector, test_i$rho)
gamma_vector <- c(gamma_vector, test_i$gamma)
}
#' maxcombo(rho = c(0, 0), gamma = c(0, 0.5))
maxcombo <- function(data, rho, gamma){
stopifnot(
is.numeric(rho), is.numeric(gamma),
rho >= 0, gamma >= 0,
length(rho) == length(gamma)
)

ans <- data |>
counting_process(arm = "experimental") |>
fh_weight(
rho_gamma = data.frame(rho = rho_vector, gamma = gamma_vector),
return_corr = TRUE)
rho_gamma = data.frame(rho = rho, gamma = gamma),
return_corr = TRUE
)

ans <- data.frame(p_value = pvalue_maxcombo(ans))

Expand Down
2 changes: 1 addition & 1 deletion R/mb_delayed_effect.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/mb_weight.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/pvalue_maxcombo.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/randomize_by_fixed_block.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/rpwexp.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/rpwexp_enroll.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/rpwexp_naive.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
2 changes: 1 addition & 1 deletion R/sim_fixed_n.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# Copyright (c) 2024 Merck & Co., Inc., Rahway, NJ, USA and its affiliates.
# All rights reserved.
#
# This file is part of the simtrial program.
Expand Down
Loading

0 comments on commit caadb3e

Please sign in to comment.