Skip to content

Commit

Permalink
add creat_arm by lose sum(accr_para) == 1 to is_wholenumber()
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleBeannie committed Feb 22, 2024
1 parent 3dae6b1 commit f8bb115
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 6 deletions.
104 changes: 100 additions & 4 deletions R/utility_wlr.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#' shape parameter for the loss to follow-up distribution
#' \item Set the scale parameter to one as the scale parameter for the loss to follow-up
#' distribution since the exponential distribution is supported only
#' \item Create arm 0 using \code{npsurvSS::create_arm()} using the parameters for arm 0.
#' \item Create arm 1 using \code{npsurvSS::create_arm()} using the parameters for arm 1.
#' \item Create arm 0 using \code{gsDesign2:::create_arm()} using the parameters for arm 0.
#' \item Create arm 1 using \code{gsDesign2:::create_arm()} using the parameters for arm 1.
#' \item Set the class of the two arms.
#' \item Return a list of the two arms.
#' }
Expand Down Expand Up @@ -87,7 +87,7 @@ gs_create_arm <- function(
loss_scale <- fail_rate$dropout_rate[1] # Only Exponential Distribution is supported

# Control Group
arm0 <- npsurvSS::create_arm(
arm0 <- create_arm(
size = 1,
accr_time = accr_time,
accr_dist = "pieceuni",
Expand All @@ -104,7 +104,7 @@ gs_create_arm <- function(


# Control Group
arm1 <- npsurvSS::create_arm(
arm1 <- create_arm(
size = ratio,
accr_time = accr_time,
accr_dist = "pieceuni",
Expand Down Expand Up @@ -271,3 +271,99 @@ gs_sigma2_wlr <- function(arm0,

return(sigma2)
}

#' @noRd
create_arm <- function(size, accr_time, accr_dist = "pieceuni",
accr_interval = c(0, accr_time),
accr_param = NA, surv_cure = 0,
surv_interval = c(0, Inf), surv_shape = 1,
surv_scale, loss_shape = 1, loss_scale,
follow_time = Inf, total_time = Inf)
{

Check warning on line 282 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=282,col=1,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.
if (!accr_dist %in% c("pieceuni", "truncexp")) {
stop("Please specify a valid accrual distribution.",
call. = F)

Check warning on line 285 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=285,col=19,[T_and_F_symbol_linter] Use FALSE instead of the symbol F.
}

accr_interval <- sort(unique(c(0, accr_interval, accr_time)))

if (min(accr_interval) < 0 | max(accr_interval) > accr_time) {

Check warning on line 290 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=290,col=30,[vector_logic_linter] Conditional expressions require scalar logical operators (&& and ||)
stop("accr_interval is out of range.", call. = F)

Check warning on line 291 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=291,col=53,[T_and_F_symbol_linter] Use FALSE instead of the symbol F.
}

if (accr_dist == "pieceuni") {
if (length(accr_param) != length(accr_interval) - 1) {
stop("Number of accrual intervals (accr_interval) does not match number of\n accrual parameters (accr_param).",

Check warning on line 296 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=296,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
call. = F)

Check warning on line 297 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=297,col=21,[T_and_F_symbol_linter] Use FALSE instead of the symbol F.
}
if (length(accr_interval) > 2 & !is_wholenumber(sum(accr_param) - 1)) {

Check warning on line 299 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=299,col=35,[vector_logic_linter] Conditional expressions require scalar logical operators (&& and ||)
stop("accr_param must sum to 1.", call. = F)

Check warning on line 300 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=300,col=50,[T_and_F_symbol_linter] Use FALSE instead of the symbol F.
}
}
else if (is.na(accr_param) | length(accr_param) > 1) {

Check warning on line 303 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=303,col=3,[brace_linter] `else` should come on the same line as the previous `}`.

Check warning on line 303 in R/utility_wlr.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utility_wlr.R,line=303,col=30,[vector_logic_linter] Conditional expressions require scalar logical operators (&& and ||)
stop("Truncated exponential is a one-parameter family distribution.",
call. = F)
}

surv_interval <- sort(unique(c(0, surv_interval, Inf)))

if (min(surv_interval) < 0) {
stop("surv_interval is out of range.", call. = F)
}

if (surv_shape != 1 & length(surv_scale) > 1) {
surv_shape <- 1
warning("Piecewise Weibull is not supported. surv_shape defaulted to 1.",
call. = F)
}

if (length(surv_scale) != length(surv_interval) - 1) {
stop("Number of survival intervals (surv_interval) does not match number of \n
piecewise hazards (surv_scale).",
call. = F)
}

if (length(loss_shape) > 1 | length(loss_scale) > 1) {
loss_shape <- loss_shape[1]
loss_scale <- loss_scale[1]
warning("Only Weibull loss to follow-up is supported. First number in loss_shape \n
and loss_scale are considered. The rest are ignored.",
call. = F)
}

if (is.infinite(follow_time) & is.infinite(total_time)) {
total_time <- 1e+06
follow_time <- total_time - accr_time
warning("Neither follow_time nor total_time were defined. Therefore, total_time is \n
defaulted to max value.",
call. = F)
}
else if (!is.infinite(follow_time) & !is.infinite(total_time) &
accr_time + follow_time != total_time) {
total_time <- accr_time + follow_time
warning("follow_time and total_time were inconsistently defined. \n
total_time will be ignored.",
call. = F)
}
else if (is.infinite(follow_time)) {
follow_time <- total_time - accr_time
}
else {
total_time <- accr_time + follow_time
}

arm <- list(size = size, accr_time = accr_time, accr_dist = accr_dist,
accr_interval = accr_interval, accr_param = accr_param,
surv_cure = surv_cure, surv_interval = surv_interval,
surv_shape = surv_shape, surv_scale = surv_scale, loss_shape = loss_shape,
loss_scale = loss_scale, follow_time = follow_time, total_time = total_time)

if (length(accr_param) == 1 & length(surv_interval) == 2 &
surv_shape == 1 & loss_shape == 1) {
class(arm) <- append(class(arm), "lachin")
}

class(arm) <- append(class(arm), "arm")

return(arm)
}
4 changes: 2 additions & 2 deletions man/gs_create_arm.Rd

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

0 comments on commit f8bb115

Please sign in to comment.