## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse   = TRUE,
  comment    = "#>",
  fig.width  = 7,
  fig.height = 4.5,
  out.width  = "100%",
  dpi        = 96
)
library(SingleArmMRCT)

## ----echo=FALSE---------------------------------------------------------------
tbl <- data.frame(
  Endpoint = c(
    "Continuous",
    "Binary",
    "Count (negative binomial)",
    "Time-to-event (hazard ratio)",
    "Milestone survival",
    "Restricted mean survival time (RMST)"
  ),
  `Calculation function` = c(
    "rcp1armContinuous()",
    "rcp1armBinary()",
    "rcp1armCount()",
    "rcp1armHazardRatio()",
    "rcp1armMilestoneSurvival()",
    "rcp1armRMST()"
  ),
  `Plot function` = c(
    "plot_rcp1armContinuous()",
    "plot_rcp1armBinary()",
    "plot_rcp1armCount()",
    "plot_rcp1armHazardRatio()",
    "plot_rcp1armMilestoneSurvival()",
    "plot_rcp1armRMST()"
  ),
  check.names = FALSE
)
knitr::kable(tbl, align = "lll")

## ----echo=FALSE---------------------------------------------------------------
params <- data.frame(
  Parameter   = c("`Nj`", "`PI`", "`approach`", "`nsim`", "`seed`"),
  Type        = c("integer vector", "numeric", "character",
                  "integer", "integer"),
  Default     = c("—", "`0.5`", '`"formula"`', "`10000`", "`1`"),
  Description = c(
    "Sample sizes for each region; length equals the number of regions $J$",
    "Effect retention threshold $\\pi$ for Method 1; must be in $[0, 1]$",
    'Calculation approach: `"formula"` or `"simulation"`',
    "Number of Monte Carlo iterations; used only when `approach = \"simulation\"`",
    "Random seed for reproducibility; used only when `approach = \"simulation\"`"
  ),
  check.names = FALSE
)
knitr::kable(params, align = "llll")

## ----echo=FALSE---------------------------------------------------------------
params_tte <- data.frame(
  Parameter   = c("`t_a`", "`t_f`", "`lambda_dropout`"),
  Type        = c("numeric", "numeric", "numeric or `NULL`"),
  Default     = c("—", "—", "`NULL`"),
  Description = c(
    "Accrual period: duration over which patients are uniformly enrolled",
    "Follow-up period: additional observation time after accrual closes; total study duration is $\\tau = t_a + t_f$",
    "Exponential dropout hazard rate; `NULL` assumes no dropout"
  ),
  check.names = FALSE
)
knitr::kable(params_tte, align = "llll")

## -----------------------------------------------------------------------------
result_formula <- rcp1armContinuous(
  mu       = 0.5,
  mu0      = 0.1,
  sd       = 1,
  Nj       = c(10, 90),
  PI       = 0.5,
  approach = "formula"
)
print(result_formula)

## -----------------------------------------------------------------------------
result_sim <- rcp1armContinuous(
  mu       = 0.5,
  mu0      = 0.1,
  sd       = 1,
  Nj       = c(10, 90),
  PI       = 0.5,
  approach = "simulation",
  nsim     = 10000,
  seed     = 1
)
print(result_sim)

## ----fig.alt="Line plot of RCP versus regional allocation proportion f1 for a continuous endpoint, comparing Method 1 and Method 2 using formula and simulation approaches across sample sizes N = 20, 40, and 100"----
plot_rcp1armContinuous(
  mu        = 0.5,
  mu0       = 0.1,
  sd        = 1,
  PI        = 0.5,
  N_vec     = c(20, 40, 100),
  J         = 3,
  nsim      = 5000,
  seed      = 1,
  base_size = 11
)

