scenario: Evaluate a Hypothetical Data Scenario for a Design

scenarioR Documentation

Evaluate a Hypothetical Data Scenario for a Design

Description

[Experimental]

scenario() is a convenience wrapper for evaluating a CRM design at a user-supplied hypothetical data scenario. It runs the model, summarizes the posterior fit, calculates the next dose recommendation, and evaluates the stopping rule for the supplied data.

Usage

scenario(object, data, mcmcOptions, ...)

## S4 method for signature 'Design,Data,McmcOptions'
scenario(object, data, mcmcOptions = McmcOptions(), ...)

## S4 method for signature 'DesignCombo,DataCombo,McmcOptions'
scenario(object, data, mcmcOptions = McmcOptions(), ...)

## S4 method for signature 'DADesign,DataDA,McmcOptions'
scenario(object, data, mcmcOptions = McmcOptions(), ...)

## S4 method for signature 'HierarchicalDesign,HierarchicalData,McmcOptions'
scenario(object, data, mcmcOptions = McmcOptions(), ...)

Arguments

object

(Design, DesignCombo, DADesign, or HierarchicalDesign)
the design to evaluate.

data

(Data, DataCombo, DataDA, or HierarchicalData)
hypothetical data scenario to evaluate.

mcmcOptions

(McmcOptions)
MCMC options for the model fit.

...

additional arguments without method dispatch.

Value

A named list containing:

  • data: the evaluated data scenario.

  • samples: posterior samples from mcmc().

  • fit: posterior model fit summary from fit().

  • dose_limit: maximum allowed next dose from the design's increment rule.

  • next_best: full next best dose recommendation from nextBest().

  • next_dose: recommended dose value for the next cohort.

  • cohort_size: active treatment cohort size at next_dose.

  • placebo_cohort_size: placebo cohort size at next_dose, if applicable.

  • stop: logical stop decision from stopTrial().

  • stop_report: named logical vector with stopping rule results.

  • stop_reason: stopping-rule message.

Functions

  • scenario(object = Design, data = Data, mcmcOptions = McmcOptions): Evaluate a hypothetical scenario for a CRM design.

  • scenario(object = DesignCombo, data = DataCombo, mcmcOptions = McmcOptions): Evaluate a hypothetical scenario for a two-drug combination CRM design.

  • scenario(object = DADesign, data = DataDA, mcmcOptions = McmcOptions): Evaluate a hypothetical scenario for a time-to-DLT augmented CRM design.

  • scenario( object = HierarchicalDesign, data = HierarchicalData, mcmcOptions = McmcOptions ): Evaluate a hypothetical scenario for a hierarchical CRM design.

Examples

# nolint start

# Define the dose-grid and a hypothetical observed data scenario.
data <- Data(
  x = c(1, 3, 3, 5, 5, 5),
  y = c(0, 0, 0, 0, 1, 0),
  cohort = c(1, 2, 2, 3, 3, 3),
  doseGrid = c(1, 3, 5, 10, 15, 20, 25)
)

# Initialize the CRM model.
model <- LogisticLogNormal(
  mean = c(-0.85, 1),
  cov = matrix(c(1, -0.5, -0.5, 1), nrow = 2),
  ref_dose = 56
)

# Choose the rule for selecting the next dose.
next_best <- NextBestNCRM(
  target = c(0.2, 0.35),
  overdose = c(0.35, 1),
  max_overdose_prob = 0.25
)

# Choose the rule for stopping.
stopping <- StoppingMinPatients(nPatients = 20) | StoppingMissingDose()

# Choose the rule for dose increments.
increments <- IncrementsRelative(
  intervals = c(0, 20),
  increments = c(1, 0.33)
)

# Initialize the design.
design <- Design(
  model = model,
  nextBest = next_best,
  stopping = stopping,
  increments = increments,
  cohort_size = CohortSizeConst(3),
  data = Data(doseGrid = data@doseGrid), # empty data here.
  startingDose = 1
)

options <- McmcOptions(
  burnin = 10,
  step = 1,
  samples = 20,
  rng_kind = "Super-Duper",
  rng_seed = 94
)


result <- scenario(design, data, options)
result$fit
result$next_dose
result$cohort_size
result$stop


# nolint end
# nolint start

# Define a hypothetical two-drug scenario.
data <- DataCombo(
  x = cbind(
    drug1 = c(10, 10, 10, 20, 20, 20),
    drug2 = c(20, 20, 20, 20, 20, 20)
  ),
  y = c(0, 0, 1, 0, 0, 0),
  doseGrid = list(drug1 = c(10, 20, 30), drug2 = c(20, 40, 60))
)

model <- TwoDrugsCombo(
  single_models = list(
    drug1 = LogisticLogNormal(
      mean = c(-0.85, 1),
      cov = matrix(c(1, -0.5, -0.5, 1), nrow = 2),
      ref_dose = 10
    ),
    drug2 = LogisticLogNormal(
      mean = c(-0.7, 0.8),
      cov = matrix(c(1.1, -0.3, -0.3, 0.9), nrow = 2),
      ref_dose = 20
    )
  ),
  gamma = 0,
  tau = 1
)

increments <- IncrementsMin(
  increments_list = list(
    IncrementsComboOneDrugOnly(),
    IncrementsComboCartesian(
      drug1 = IncrementsRelative(intervals = c(0), increments = c(1)),
      drug2 = IncrementsRelative(intervals = c(0), increments = c(1))
    )
  )
)

design <- DesignCombo(
  model = model,
  nextBest = NextBestNCRM(
    target = c(0.2, 0.35),
    overdose = c(0.35, 1),
    max_overdose_prob = 0.25
  ),
  stopping = StoppingMinPatients(nPatients = 20),
  increments = increments,
  cohort_size = CohortSizeConst(3),
  data = DataCombo(doseGrid = data@doseGrid),
  startingDose = c(drug1 = 10, drug2 = 20)
)

options <- McmcOptions(
  burnin = 10,
  step = 1,
  samples = 20,
  rng_kind = "Super-Duper",
  rng_seed = 94
)


result <- scenario(design, data, options)
result$fit
result$next_dose
result$cohort_size
result$stop


# nolint end
# nolint start

# Define a hypothetical time-to-DLT scenario.
data <- DataDA(
  x = c(0.1, 0.5, 1.5, 3, 6, 10, 10, 10),
  y = c(0, 0, 1, 1, 0, 0, 1, 0),
  u = c(42, 30, 15, 5, 20, 25, 30, 60),
  t0 = c(0, 15, 30, 40, 55, 70, 75, 85),
  Tmax = 60,
  doseGrid = c(0.1, 0.5, 1.5, 3, 6, seq(from = 10, to = 80, by = 2)),
  ID = 1L:8L,
  cohort = as.integer(c(1, 2, 3, 4, 5, 6, 6, 6))
)

npiece <- 10
t_max <- 60
lambda_prior <- function(k) {
  npiece / (t_max * (npiece - k + 0.5))
}

model <- DALogisticLogNormal(
  mean = c(-0.85, 1),
  cov = matrix(c(1, -0.5, -0.5, 1), nrow = 2),
  ref_dose = 56,
  npiece = npiece,
  l = as.numeric(t(apply(as.matrix(c(1:npiece), 1, npiece), 2, lambda_prior))),
  c_par = 2
)

size1 <- CohortSizeRange(
  intervals = c(0, 30),
  cohort_size = c(1, 3)
)
size2 <- CohortSizeDLT(
  intervals = c(0, 1),
  cohort_size = c(1, 3)
)

design <- DADesign(
  model = model,
  increments = IncrementsRelative(
    intervals = c(0, 20),
    increments = c(1, 0.33)
  ),
  nextBest = NextBestNCRM(
    target = c(0.2, 0.35),
    overdose = c(0.35, 1),
    max_overdose_prob = 0.25
  ),
  stopping = StoppingTargetProb(
    target = c(0.2, 0.35),
    prob = 0.5
  ) | StoppingMinPatients(nPatients = 50) | StoppingMissingDose(),
  cohort_size = maxSize(size1, size2),
  data = DataDA(doseGrid = data@doseGrid, Tmax = data@Tmax),
  safetyWindow = SafetyWindowConst(c(6, 2), 7, 7),
  startingDose = 3
)

options <- McmcOptions(
  burnin = 10,
  step = 1,
  samples = 20,
  rng_kind = "Super-Duper",
  rng_seed = 94
)


result <- scenario(design, data, options)
result$fit
result$next_dose
result$cohort_size
result$stop


# nolint end
# nolint start

dose_grid <- c(1, 3, 5, 10, 15, 20, 25)

# Define hypothetical observed data for two related arms.
data <- HierarchicalData(
  arm_a = Data(
    x = c(1, 3, 3, 5),
    y = c(0, 0, 0, 1),
    cohort = c(1, 2, 2, 3),
    doseGrid = dose_grid
  ),
  arm_b = Data(
    x = c(1, 1, 3, 3),
    y = c(0, 0, 0, 0),
    cohort = c(1, 1, 2, 2),
    doseGrid = dose_grid
  )
)

model_a <- LogisticLogNormal(
  mean = c(-0.85, 1),
  cov = matrix(c(1, -0.5, -0.5, 1), nrow = 2),
  ref_dose = 10
)
model_b <- LogisticLogNormal(
  mean = c(-0.85, 1),
  cov = matrix(c(1, -0.5, -0.5, 1), nrow = 2),
  ref_dose = 10
)

next_best <- NextBestNCRM(
  target = c(0.2, 0.35),
  overdose = c(0.35, 1),
  max_overdose_prob = 0.25
)
stopping <- StoppingMinPatients(nPatients = 20) | StoppingMissingDose()
increments <- IncrementsRelative(
  intervals = c(0, 20),
  increments = c(1, 0.33)
)

design_a <- Design(
  model = model_a,
  nextBest = next_best,
  stopping = stopping,
  increments = increments,
  cohort_size = CohortSizeConst(3),
  data = Data(doseGrid = dose_grid),
  startingDose = 1
)
design_b <- Design(
  model = model_b,
  nextBest = next_best,
  stopping = stopping,
  increments = increments,
  cohort_size = CohortSizeConst(3),
  data = Data(doseGrid = dose_grid),
  startingDose = 1
)

design <- HierarchicalDesign(
  DesignArm(
    name = "arm_a",
    design = design_a
  ),
  DesignArm(
    name = "arm_b",
    design = design_b
  ),
  exchangeable_parameters = list(
    intercept = list(
      arm_a = "alpha0",
      arm_b = "alpha0"
    ),
    slope = list(
      arm_a = "alpha1",
      arm_b = "alpha1"
    )
  )
)

options <- McmcOptions(
  burnin = 10,
  step = 1,
  samples = 20,
  rng_kind = "Super-Duper",
  rng_seed = 94
)


result <- scenario(design, data, options)
result$fit
result$next_dose
result$cohort_size
result$stop


# nolint end

crmPack documentation built on July 5, 2026, 9:06 a.m.