Skip to content

Commit

Permalink
Merge pull request #228 from Merck/spelling
Browse files Browse the repository at this point in the history
Fix spelling and run styler
  • Loading branch information
LittleBeannie authored Apr 16, 2024
2 parents 75d7b67 + b26634c commit 42290ea
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 80 deletions.
6 changes: 3 additions & 3 deletions R/counting_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#'
#' Produces a data frame that is sorted by stratum and time.
#' Included in this is only the times at which one or more event occurs.
#' The output dataset contains stratum, tte (time-to-event),
#' at risk count and count of events at the specified tte
#' sorted by stratum and tte.
#' The output dataset contains stratum, TTE (time-to-event),
#' at risk count, and count of events at the specified TTE
#' sorted by stratum and TTE.
#'
#' @details
#' The function only considered two group situation.
Expand Down
2 changes: 0 additions & 2 deletions R/early_zero_weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#' @importFrom data.table ":=" as.data.table fifelse merge.data.table setDF
#' @noRd
early_zero_weight <- function(x, early_period = 4, fail_rate = NULL) {


ans <- as.data.table(x)
n_stratum <- length(unique(ans$stratum))

Expand Down
4 changes: 1 addition & 3 deletions R/fh_weight.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ fh_weight <- function(
counting_process(arm = "experimental"),
rho = 0,
gamma = 1) {


# Input checking ----
if(length(rho) != 1 || length(gamma) != 1) {
if (length(rho) != 1 || length(gamma) != 1) {
stop("fh_weight: please input single numerical values of rho and gamma.")
}

Expand Down
31 changes: 17 additions & 14 deletions R/maxcombo.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#' Maxcombo test
#' 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 data A TTE dataset.
#' @param rho Numeric vector. Must be greater
#' than or equal to zero. Must be the same length as `gamma`.
#' @param gamma Numeric vector. Must be
Expand All @@ -37,9 +37,10 @@
#' parameters of this test method (`parameter`),
#' point estimation of the treatment effect (`estimation`),
#' standardized error of the treatment effect (`se`),
#' Z-score of each test of the Maxcombo (`z`),
#' Z-score of each test of the MaxCombo (`z`),
#' p-values (`p_value`)
#' and the correlation matrix of each tests in Maxcombo (begin with `v`)
#' and the correlation matrix of each tests in MaxCombo (begin with `v`)
#'
#' @export
#'
#' @seealso [wlr()], [rmst()], [milestone()]
Expand All @@ -48,15 +49,16 @@
#' sim_pw_surv(n = 200) |>
#' cut_data_by_event(150) |>
#' maxcombo(rho = c(0, 0), gamma = c(0, 1), return_corr = TRUE)
maxcombo <- function(data = sim_pw_surv(n = 200) |> cut_data_by_event(150),
rho = c(0, 0, 1),
gamma = c(0, 1, 1),
return_variance = FALSE,
return_corr = FALSE) {
maxcombo <- function(
data = sim_pw_surv(n = 200) |> cut_data_by_event(150),
rho = c(0, 0, 1),
gamma = c(0, 1, 1),
return_variance = FALSE,
return_corr = FALSE) {
# Input checking ----
n_weight <- length(rho)

if(any(!is.numeric(rho)) || any(!is.numeric(gamma)) || any(rho < 0) || any(gamma < 0)) {
if (any(!is.numeric(rho)) || any(!is.numeric(gamma)) || any(rho < 0) || any(gamma < 0)) {
stop("maxcombo: please input positive values of rho and gamma.")
}

Expand All @@ -80,10 +82,10 @@ maxcombo <- function(data = sim_pw_surv(n = 200) |> cut_data_by_event(150),
# We want ave_rho[i,j] = (rho[i] + rho[j])/2
# and ave_gamma[i,j] = (gamma[i] + gamma[j])/2
ave_rho <- (matrix(rho, nrow = n_weight, ncol = n_weight, byrow = FALSE) +
matrix(rho, nrow = n_weight, ncol = n_weight, byrow = TRUE)
matrix(rho, nrow = n_weight, ncol = n_weight, byrow = TRUE)
) / 2
ave_gamma <- (matrix(gamma, nrow = n_weight, ncol = n_weight) +
matrix(gamma, nrow = n_weight, ncol = n_weight, byrow = TRUE)
matrix(gamma, nrow = n_weight, ncol = n_weight, byrow = TRUE)
) / 2

# Convert to all original and average rho/gamma into a data.table ----
Expand Down Expand Up @@ -117,11 +119,12 @@ maxcombo <- function(data = sim_pw_surv(n = 200) |> cut_data_by_event(150),
y = res |> as.data.frame(),
by = c("rho", "gamma"),
all.x = TRUE,
sort = FALSE)
sort = FALSE
)

# Tidy outputs ----
ans <- list()
ans$method <- "Maxcombo"
ans$method <- "MaxCombo"
temp <- data.frame(rho = rho, gamma = gamma)
temp$x <- paste0("FH(", temp$rho, ", ", temp$gamma, ")")
ans$parameter <- paste(temp$x, collapse = " + ")
Expand Down
32 changes: 18 additions & 14 deletions R/sim_fixed_n.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
#' x <- sim_fixed_n(
#' n_sim = 10,
#' timing_type = 2,
#' rho_gamma = data.frame(rho = 0, gamma = c(0, 1)))
#' rho_gamma = data.frame(rho = 0, gamma = c(0, 1))
#' )
#'
#' # Get power approximation
#' x |>
Expand Down Expand Up @@ -135,7 +136,6 @@ sim_fixed_n <- function(
# Default is to to logrank testing, but one or more Fleming-Harrington tests
# can be specified
rho_gamma = data.frame(rho = 0, gamma = 0)) {

# Check input values ----
# Check input enrollment rate assumptions
if (!("duration" %in% names(enroll_rate))) {
Expand Down Expand Up @@ -264,7 +264,7 @@ sim_fixed_n <- function(
dropout_rate = dr,
block = block
)
#for (i in 1:n_sim) {
# for (i in 1:n_sim) {

# Calculate possible cutting dates ----
# Date 1: Study date that targeted event rate achieved
Expand Down Expand Up @@ -383,21 +383,25 @@ doAnalysis <- function(d, rho_gamma, n_stratum) {
res <- d |>
wlr(weight = fh(rho = rho_gamma$rho, gamma = rho_gamma$gamma))

ans <- data.frame(method = res$method,
parameter = res$parameter,
estimation = res$estimation,
se = res$se,
z = res$z)
ans <- data.frame(
method = res$method,
parameter = res$parameter,
estimation = res$estimation,
se = res$se,
z = res$z
)
} else {
res <- d |>
maxcombo(rho = rho_gamma$rho, gamma = rho_gamma$gamma, return_corr = TRUE)

ans <- data.frame(method = rep(res$method, nrow(rho_gamma)),
parameter = rep(res$parameter, nrow(rho_gamma)),
estimation = rep("-", nrow(rho_gamma)),
se = rep("-", nrow(rho_gamma)),
z = res$z,
p_value = rep(res$p_value, nrow(rho_gamma)))
ans <- data.frame(
method = rep(res$method, nrow(rho_gamma)),
parameter = rep(res$parameter, nrow(rho_gamma)),
estimation = rep("-", nrow(rho_gamma)),
se = rep("-", nrow(rho_gamma)),
z = res$z,
p_value = rep(res$p_value, nrow(rho_gamma))
)
ans <- cbind(ans, res$corr |> as.data.frame())
}

Expand Down
10 changes: 4 additions & 6 deletions R/wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

#' Weighted logrank test
#'
#' @param data cutted dataset generated by sim_pw_surv
#' @param weight weighting functions, such as [fh()], [mb()], and
#' @param data Dataset that has been cut, generated by [sim_pw_surv()].
#' @param weight Weighting functions, such as [fh()], [mb()], and
#' [early_zero()].
#' @param return_variance A logical flag that, if `TRUE`, adds columns
#' estimated variance for weighted sum of observed minus expected;
#' see details; Default: `FALSE`.
#'
#' @return A list contraining the test method (`method`),
#' @return A list containing the test method (`method`),
#' parameters of this test method (`parameter`),
#' point estimation of the treatment effect (`estimation`),
#' standardized error of the treatment effect (`se`),
Expand All @@ -34,6 +34,7 @@
#' @importFrom data.table setDF setDT
#'
#' @export
#'
#' @details
#' - \eqn{z} - Standardized normal Fleming-Harrington weighted logrank test.
#' - \eqn{i} - Stratum index.
Expand Down Expand Up @@ -97,23 +98,20 @@ wlr <- function(data, weight, return_variance = FALSE) {
ans$estimation <- sum(x$weight * x$o_minus_e)
ans$se <- sqrt(sum(x$weight^2 * x$var_o_minus_e))
ans$z <- ans$estimation / ans$se

} else if (inherits(weight, "mb")) {
x <- x |> mb_weight(delay = weight$delay, w_max = weight$w_max)

ans$parameter <- paste0("MB(delay = ", weight$delay, ", max_weight = ", weight$w_max, ")")
ans$estimate <- sum(x$o_minus_e * x$mb_weight)
ans$se <- sqrt(sum(x$var_o_minus_e * x$mb_weight^2))
ans$z <- ans$estimate / ans$se

} else if (inherits(weight, "early_period")) {
x <- x |> early_zero_weight(early_period = weight$early_period, fail_rate = weight$fail_rate)

ans$parameter <- paste0("Xu 2017 with first ", weight$early_period, " months of 0 weights")
ans$estimate <- sum(x$o_minus_e * x$weight)
ans$se <- sqrt(sum(x$var_o_minus_e * x$weight^2))
ans$z <- ans$estimate / ans$se

}
return(ans)
}
82 changes: 82 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
batchtools
biomarker
biometrical
biopharmaceutical
blazingly
documentable
doi
downweighting
durations
errantly
frac
geq
gsDesign
immuno
ldots
logrank
magrittr
modestWLRT
multisession
nonproportional
operatorname
parallelization
parallelize
pharma
pkgdown
reproducibility
survRM
tidyverse
topologies
unadjusted
unstratified
widehat
ANCOVA
Bo
Breslow's
Burman
CMD
Codecov
Foulkes
Fredrik
Freidlin
Guo
Harhoff
HPC
Hu
Iacona
Ji
Jian
Jing
Kaplan
Korn
Lachin
Liao
Liu
Luo
Magirr
MaxCombo
Mukhopadhyay
MWLRT
Pralay
Qin
Rahway
RMST
RMTL
Rong
Roychoudhury
RStudio
Rui
Satrajit
Tai
Tatsuoka
Tianle
Tsang
Tsiatis
TTE
WPGSD
Xiaodong
Xu
Xuejing
YAML
Zhen
Zifang
6 changes: 3 additions & 3 deletions man/counting_process.Rd

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

8 changes: 4 additions & 4 deletions man/maxcombo.Rd

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

3 changes: 2 additions & 1 deletion man/sim_fixed_n.Rd

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

6 changes: 3 additions & 3 deletions man/wlr.Rd

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

Loading

0 comments on commit 42290ea

Please sign in to comment.