Skip to content

Commit

Permalink
Pass the number of control and experimental treatments as attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jdblischak committed Aug 27, 2024
1 parent de83a45 commit f0de8b8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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.4.1.9
Version: 0.4.1.10
Authors@R: c(
person("Keaven", "Anderson", email = "[email protected]", role = c("aut")),
person("Yujie", "Zhao", email = "[email protected]", role = c("ctb","cre")),
Expand Down
9 changes: 8 additions & 1 deletion R/counting_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@
#' @details
#' The output produced by [counting_process()] produces a
#' counting process dataset grouped by stratum and sorted within stratum
#' by increasing times where events occur.
#' by increasing times where events occur. The object is assigned the class
#' "counting_process". It also has the attributes "control" and "experimental",
#' which are the totals of the control and experimental treatments,
#' respectively, from the input time-to-event data.
#'
#' @examples
#' # Example 1
Expand Down Expand Up @@ -144,6 +147,10 @@ counting_process <- function(x, arm) {

setDF(ans)
class(ans) <- c("counting_process", class(ans))
# Record number of control and experimental treatments, which is required for
# downstream test function wlr()
attr(ans, "control") <- sum(x$treatment == "control")
attr(ans, "experimental") <- sum(x$treatment == "experimental")

return(ans)
}
2 changes: 1 addition & 1 deletion R/wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ wlr.counting_process <- function(data, weight, return_variance = FALSE) {

# calculate the sample size and randomization ratio
n <- nrow(data)
ratio <- sum(data$treatment == "experimental") / sum(data$treatment == "control")
ratio <- attr(data, "experimental") / attr(data, "control")
q_e <- ratio / (1 + ratio)
q_c <- 1 - q_e

Expand Down
5 changes: 4 additions & 1 deletion man/counting_process.Rd

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

0 comments on commit f0de8b8

Please sign in to comment.