Skip to contents

Rounds sample size to an even number for equal design

Usage

to_integer(x, ...)

# S3 method for fixed_design
to_integer(x, sample_size = TRUE, ...)

# S3 method for gs_design
to_integer(x, sample_size = TRUE, ...)

Arguments

x

An object returned by fixed_design_xxx() and gs_design_xxx().

...

Additional parameters (not used).

sample_size

Logical, indicting if ceiling sample size to an even integer.

Value

A list similar to the output of fixed_design_xxx() and gs_design_xxx(), except the sample size is an integer.

Examples

library(dplyr)
library(gsDesign2)

# Average hazard ratio
# \donttest{
x <- fixed_design_ahr(
  alpha = .025, power = .9,
  enroll_rate = define_enroll_rate(duration = 18, rate = 1),
  fail_rate = define_fail_rate(
    duration = c(4, 100),
    fail_rate = log(2) / 12, hr = c(1, .6),
    dropout_rate = .001
  ),
  study_duration = 36
)
x |>
  to_integer() |>
  summary()
#> # A tibble: 1 × 7
#>   Design                   N Events  Time Bound alpha Power
#>   <chr>                <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Average hazard ratio   464   325.  35.9  1.96 0.025 0.900

# FH
x <- fixed_design_fh(
  alpha = 0.025, power = 0.9,
  enroll_rate = define_enroll_rate(duration = 18, rate = 20),
  fail_rate = define_fail_rate(
    duration = c(4, 100),
    fail_rate = log(2) / 12,
    hr = c(1, .6),
    dropout_rate = .001
  ),
  rho = 0.5, gamma = 0.5,
  study_duration = 36, ratio = 1
)
x |>
  to_integer() |>
  summary()
#> # A tibble: 1 × 7
#>   Design                              N Events  Time Bound alpha Power
#>   <chr>                           <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Fleming-Harrington FH(0.5, 0.5)   378   264.  35.8  1.96 0.025 0.900

# MB
x <- fixed_design_mb(
  alpha = 0.025, power = 0.9,
  enroll_rate = define_enroll_rate(duration = 18, rate = 20),
  fail_rate = define_fail_rate(
    duration = c(4, 100),
    fail_rate = log(2) / 12, hr = c(1, .6),
    dropout_rate = .001
  ),
  tau = 4,
  study_duration = 36, ratio = 1
)
x |>
  to_integer() |>
  summary()
#> # A tibble: 1 × 7
#>   Design                            N Events  Time Bound alpha Power
#>   <chr>                         <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Modestly weighted LR: tau = 4   430   302.  36.1  1.96 0.025 0.901
# }
# \donttest{
# Example 1: Information fraction based spending
gs_design_ahr(
  analysis_time = c(18, 30),
  upper = gs_spending_bound,
  upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL),
  lower = gs_b,
  lpar = c(-Inf, -Inf)
) |>
  to_integer() |>
  summary()
#> # A tibble: 2 × 7
#> # Groups:   Analysis [2]
#>   Analysis         Bound     Z `~HR at bound` `Nominal p` `Alternate hypothesis`
#>   <chr>            <chr> <dbl>          <dbl>       <dbl>                  <dbl>
#> 1 Analysis: 1 Tim… Effi…  2.57          0.696      0.005                   0.288
#> 2 Analysis: 2 Tim… Effi…  1.99          0.799      0.0234                  0.901
#> # ℹ 1 more variable: `Null hypothesis` <dbl>

gs_design_wlr(
  analysis_time = c(18, 30),
  upper = gs_spending_bound,
  upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL),
  lower = gs_b,
  lpar = c(-Inf, -Inf)
) |>
  to_integer() |>
  summary()
#> # A tibble: 2 × 7
#> # Groups:   Analysis [2]
#>   Analysis        Bound     Z `~wHR at bound` `Nominal p` `Alternate hypothesis`
#>   <chr>           <chr> <dbl>           <dbl>       <dbl>                  <dbl>
#> 1 Analysis: 1 Ti… Effi…  2.57           0.700      0.0051                  0.289
#> 2 Analysis: 2 Ti… Effi…  1.99           0.802      0.0234                  0.900
#> # ℹ 1 more variable: `Null hypothesis` <dbl>

gs_design_rd(
  p_c = tibble::tibble(stratum = c("A", "B"), rate = c(.2, .3)),
  p_e = tibble::tibble(stratum = c("A", "B"), rate = c(.15, .27)),
  weight = "ss",
  stratum_prev = tibble::tibble(stratum = c("A", "B"), prevalence = c(.4, .6)),
  info_frac = c(0.7, 1),
  upper = gs_spending_bound,
  upar = list(sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL),
  lower = gs_b,
  lpar = c(-Inf, -Inf)
) |>
  to_integer() |>
  summary()
#> # A tibble: 2 × 7
#> # Groups:   Analysis [2]
#>   Analysis Bound     Z ~Risk difference at …¹ `Nominal p` `Alternate hypothesis`
#>   <chr>    <chr> <dbl>                  <dbl>       <dbl>                  <dbl>
#> 1 Analysi… Effi…  2.44                 0.0339      0.0074                  0.616
#> 2 Analysi… Effi…  2                    0.0232      0.0228                  0.901
#> # ℹ abbreviated name: ¹​`~Risk difference at bound`
#> # ℹ 1 more variable: `Null hypothesis` <dbl>

# Example 2: Calendar based spending
x <- gs_design_ahr(
  upper = gs_spending_bound,
  analysis_time = c(18, 30),
  upar = list(
    sf = gsDesign::sfLDOF, total_spend = 0.025, param = NULL,
    timing = c(18, 30) / 30
  ),
  lower = gs_b,
  lpar = c(-Inf, -Inf)
) |> to_integer()

# The IA nominal p-value is the same as the IA alpha spending
x$bound$`nominal p`[1]
#> [1] 0.003808063
gsDesign::sfLDOF(alpha = 0.025, t = 18 / 30)$spend
#> [1] 0.003808063
# }