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

Enhance documention in define.R #305

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 39 additions & 13 deletions R/define.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@

#' Define enrollment rate
#'
#' @param duration A numeric vector of piecewise study duration interval.
#' Define the enrollment rate of subjects for a study as following a piecewise
#' exponential distribution.
#'
#' @details
#' The `duration` are ordered piecewise for a duration equal to
#' \eqn{t_i - t_{i-1}}, where \eqn{0 = t_0 < t_i < \cdots < t_M = \infty}.
#' The enrollment rates are defined in each duration with the same length.
#'
#' For a study with multiple strata, different duration and rates can be
#' specified in each stratum.
#'
#' @param duration A numeric vector of ordered piecewise study duration interval.
#' @param rate A numeric vector of enrollment rate in each `duration`.
#' @param stratum A character vector of stratum name.
#'
Expand All @@ -35,9 +46,9 @@
#'
#' # Define enroll rate with stratum
#' define_enroll_rate(
#' stratum = c("low", "low", "high"),
#' duration = c(2, 2, 10),
#' rate = c(3, 6, 9)
#' duration = rep(c(2, 2, 2, 18), 3),
#' rate = c((1:4) / 3, (1:4) / 2, (1:4) / 6),
#' stratum = c(array("High", 4), array("Moderate", 4), array("Low", 4))
#' )
define_enroll_rate <- function(
duration,
Expand Down Expand Up @@ -74,20 +85,35 @@ define_enroll_rate <- function(
df
}

#' Define fail rate
#' Define failure rate
#'
#' Define subject failure rate for a study with two treatment groups.
#' Also supports stratified designs that have different failure rates in
#' each stratum.
#'
#' @param duration A numeric vector of piecewise study duration interval.
#' @param fail_rate A numeric vector of failure rate in each `duration`.
#' @details
#' Define the failure and dropout rate of subjects for a study as following
#' a piecewise exponential distribution.
#' The `duration` are ordered piecewise for a duration equal to
#' \eqn{t_i - t_{i-1}}, where \eqn{0 = t_0 < t_i < \cdots < t_M = \infty}.
#' The failure rate, dropout rate, and hazard ratio in a study duration
#' can be specified.
#'
#' For a study with multiple strata, different duration, failure rates,
#' dropout rates, and hazard ratios can be specified in each stratum.
#'
#' @param duration A numeric vector of ordered piecewise study duration interval.
#' @param fail_rate A numeric vector of failure rate in each `duration` in the control group.
#' @param dropout_rate A numeric vector of dropout rate in each `duration`.
#' @param hr A numeric vector of hazard ratio.
#' @param hr A numeric vector of hazard ratio between treatment and control group.
#' @param stratum A character vector of stratum name.
#'
#' @return A `fail_rate` data frame.
#'
#' @export
#'
#' @examples
#' # Define enroll rate without stratum
#' # Define enroll rate
#' define_fail_rate(
#' duration = c(3, 100),
#' fail_rate = log(2) / c(9, 18),
Expand All @@ -97,11 +123,11 @@ define_enroll_rate <- function(
#'
#' # Define enroll rate with stratum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both examples, please please consider explaining in plain language what are being defined - this is because something looks natural to you doesn't mean it's "self-explanatory" to all - maybe it's because you are more familiar with the spec. 🙏

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc are updated. Please take another look to see if it is clear.

#' define_fail_rate(
#' duration = c(3, 100),
#' fail_rate = log(2) / c(9, 18),
#' hr = c(.9, .6),
#' stratum = c(rep("Low", 2), rep("High", 2)),
#' duration = 1,
#' fail_rate = c(.1, .2, .3, .4),
#' dropout_rate = .001,
#' stratum = c("low", "high")
#' hr = c(.9, .75, .8, .6)
#' )
define_fail_rate <- function(
duration,
Expand Down
19 changes: 14 additions & 5 deletions man/define_enroll_rate.Rd

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

33 changes: 23 additions & 10 deletions man/define_fail_rate.Rd

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

Loading