sequential_analysis: Analyse accumulated real data at a sequential interim look

View source: R/sequential-analysis.R

sequential_analysisR Documentation

Analyse accumulated real data at a sequential interim look

Description

Fits the prespecified model to the data accumulated so far, computes the monitored posterior probability, applies the prespecified stopping threshold for the current look, and records the result in an auditable monitor object. Call it once per interim look, passing the design on the first call and the returned monitor object on subsequent calls.

The monitor refuses to continue after a stop decision has been recorded unless allow_after_stop = TRUE, in which case the continuation is logged as a protocol deviation. Analyses at sample sizes that do not match the planned schedule are permitted but flagged and recorded.

Usage

sequential_analysis(
  x,
  data,
  Ntrials_col = NULL,
  allow_after_stop = FALSE,
  note = NULL,
  inla_num_threads = NULL
)

Arguments

x

A "powerbrmsINLA_seq_design" (first look) or "powerbrmsINLA_seq_monitor" (subsequent looks).

data

Data frame containing all data accumulated so far (not just the new batch). Must contain the variables in the design formula.

Ntrials_col

Optional name of a column with binomial trial counts (binomial/beta-binomial families). Defaults to a column named .Ntrials if present, else 1 (Bernoulli).

allow_after_stop

Logical; permit analysis after a recorded stop decision (logged as a deviation). Default FALSE.

note

Optional character note recorded with this look (e.g. reason for an off-schedule analysis).

inla_num_threads

INLA threads ("outer:inner"); auto-detected if NULL.

Value

A list of class "powerbrmsINLA_seq_monitor" containing the design, its fingerprint, a looks data frame (one row per analysis: timestamp, n, planned n, estimate, credible interval, monitored probability, thresholds, decision, deviations), and the current status ("ongoing" or a stop decision).

See Also

sequential_design(), plot_sequential_monitor(), brms_inla_sequential_trial()

Examples

## Not run: 
design <- sequential_design(
  formula = y ~ treatment, effect_name = "treatment",
  metric = "direction", looks = c(40, 80, 120),
  prob_success = 0.95, prob_futility = 0.05
)

# After the first 40 observations have been collected:
mon <- sequential_analysis(design, data_so_far)
print(mon)

# After 80:
mon <- sequential_analysis(mon, data_so_far)
plot_sequential_monitor(mon)

## End(Not run)


powerbrmsINLA documentation built on July 2, 2026, 5:07 p.m.