tests/winratiosim-tests.R

library(winratiosim)

ci <- binom.conf.exact(8, 10)
stopifnot(
  length(ci) == 3L,
  ci[["PointEst"]] == 0.8,
  ci[["Lower"]] < ci[["PointEst"]],
  ci[["Upper"]] > ci[["PointEst"]]
)

tte_pairs <- data.frame(
  usubjid1 = c(1, 1),
  usubjid2 = c(2, 3),
  deathdays1 = c(360, 120),
  deathdays2 = c(100, 200),
  death1 = c(0, 1),
  death2 = c(1, 1),
  score = NA_real_,
  WR_cat = ""
)
tte_scored <- Scoring_TTE(tte_pairs, "deathdays1", "deathdays2",
                          "death1", "death2")
stopifnot(identical(tte_scored$score, c(1, -1)))

continuous_pairs <- data.frame(
  usubjid1 = c(1, 1, 2),
  usubjid2 = c(3, 4, 4),
  kccq1 = c(15, 10, NA),
  kccq2 = c(10, 10, 12),
  score = NA_real_,
  WR_cat = ""
)
continuous_scored <- Scoring_Conti(
  continuous_pairs,
  higher_better = "Yes",
  var1 = "kccq1",
  var2 = "kccq2"
)
stopifnot(identical(continuous_scored$score, c(1, 0, NA_real_)))

sim <- winratiosim(
  nsim = 2,
  N = 20,
  Randomization.ratio = c(1, 1),
  alpha.JFM = 0,
  theta.JFM = 1,
  lambda_trt = 0.13,
  lambda_ctl = 0.15,
  ann.icr_trt = 0.32,
  ann.icr_ctl = 0.55,
  xbase_trt = 45,
  xfinal_trt = 52.5,
  xbase_ctl = 45,
  xfinal_ctl = 45,
  sd.delta.x_trt = 20,
  sd.delta.x_ctl = 20,
  censorrate_trt = 0.2,
  censorrate_ctl = 0.2,
  nc = 1,
  seed = 2025
)

stopifnot(
  is.list(sim),
  nrow(sim$df_WR.analysis.summary) == 2L,
  nrow(sim$df_FS.analysis.summary) == 2L,
  nrow(sim$df_sample.size.summary) == 2L,
  all(c("Prob_of_Win_trt", "Prob_of_tie", "Prob_of_Win_ctl", "ALL") %in%
        names(sim$df_Total_probability))
)

Try the winratiosim package in your browser

Any scripts or data that you put into this service are public.

winratiosim documentation built on July 7, 2026, 1:07 a.m.