| Title: | Randomization, Allocation Concealment and Blinding for Clinical Trials |
|---|---|
| Description: | Provides reproducible trial-design infrastructure for simple, permuted-block, stratified-block, and Pocock-Simon minimization randomization. Sealed allocation sequences, deterministic audit fingerprints, treatment-code management, append-only unblinding logs, CONSORT/SPIRIT operations, adverse-event summaries, explicit analysis populations, missing-data hooks, and endpoint-analysis wrappers support auditable clinical-trial workflows. Deterministic CDISC SDTM-shaped and ADaM-shaped exports provide linked tabulation and analysis datasets without claiming external regulatory conformance. |
| Authors: | Yusuke Matsui [aut, cre] |
| Maintainer: | Yusuke Matsui <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.5.1 |
| Built: | 2026-10-03 13:42:01 UTC |
| Source: | https://github.com/x-biosignal/PhysioTrial |
Creates one typed adverse-event row. CTCAE severity and regulatory seriousness are stored independently; a serious event is not inferred from a grade threshold. MedDRA fields preserve externally assigned coding metadata and are not checked against a bundled terminology.
adverseEvent( participant_id, term, onset_date, end_date = as.Date(NA), ctcae_grade, serious = FALSE, causality = c("not_assessed", "unrelated", "unlikely", "possible", "probable", "definite"), action = NA_character_, outcome = c("unknown", "not_recovered", "recovering", "recovered", "recovered_with_sequelae", "fatal"), meddra_pt = NA_character_, meddra_code = NA_character_, meddra_version = NA_character_, metadata = list() )adverseEvent( participant_id, term, onset_date, end_date = as.Date(NA), ctcae_grade, serious = FALSE, causality = c("not_assessed", "unrelated", "unlikely", "possible", "probable", "definite"), action = NA_character_, outcome = c("unknown", "not_recovered", "recovering", "recovered", "recovered_with_sequelae", "fatal"), meddra_pt = NA_character_, meddra_code = NA_character_, meddra_version = NA_character_, metadata = list() )
participant_id |
Non-empty participant identifier. |
term |
Verbatim adverse-event term. |
onset_date |
Event onset date. |
end_date |
Optional event end date. |
ctcae_grade |
Integer CTCAE grade from 1 through 5. |
serious |
Whether the event meets a seriousness criterion. |
causality |
Investigator causality assessment. |
action |
Optional action taken. |
outcome |
Controlled event outcome. |
meddra_pt |
Optional MedDRA preferred term. |
meddra_code |
Optional MedDRA code. |
meddra_version |
Optional MedDRA version. |
metadata |
Free-form list stored as a list-column. |
A one-row adverse_event data frame.
National Cancer Institute. CTCAE version 5.0.
adverseEvent( "P001", "Nausea", as.Date("2026-01-02"), ctcae_grade = 2, causality = "possible" )adverseEvent( "P001", "Nausea", as.Date("2026-01-02"), ctcae_grade = 2, causality = "possible" )
Reports event counts separately from participant incidence, and counts SAE
status from the explicit serious field rather than a CTCAE grade cutoff.
aeSummary(events, allocation, arms = NULL)aeSummary(events, allocation, arms = NULL)
events |
List of |
allocation |
Data frame with unique |
arms |
Optional complete arm order, including zero-event arms. |
An ae_summary with arm, severity, and term tables.
allocation <- data.frame( participant_id = c("p1", "p2"), arm = c("active", "control") ) events <- list(adverseEvent( "p1", "Nausea", as.Date("2026-01-02"), ctcae_grade = 1 )) aeSummary(events, allocation, arms = c("active", "control"))allocation <- data.frame( participant_id = c("p1", "p2"), arm = c("active", "control") ) events <- list(adverseEvent( "p1", "Nausea", as.Date("2026-01-02"), ctcae_grade = 1 )) aeSummary(events, allocation, arms = c("active", "control"))
Allocation Ratio
allocationRatio(x) ## S4 method for signature 'Trial' allocationRatio(x)allocationRatio(x) ## S4 method for signature 'Trial' allocationRatio(x)
x |
A Trial object. |
Named integer vector of allocation weights.
allocationRatio(Trial("T1", c("active", "control")))allocationRatio(Trial("T1", c("active", "control")))
Counts use revealed rows only. The stratum value "__overall__" denotes
totals across all revealed strata.
allocationTable(seq) ## S4 method for signature 'RandomizationSequence' allocationTable(seq)allocationTable(seq) ## S4 method for signature 'RandomizationSequence' allocationTable(seq)
seq |
A RandomizationSequence object. |
Data frame with stratum, arm, and n columns.
sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) allocationTable(sequence)sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) allocationTable(sequence)
Filters outcome rows to analysis-set members. LOCF is included only for legacy and sensitivity workflows; it is generally unsuitable for primary confirmatory inference. Multiple imputation requires an explicit callback and never silently substitutes a single imputation.
analysisData( set, outcomes, id_col = "id", time_col = NULL, value_cols = NULL, missing = c("none", "locf", "multiple"), imputer = NULL, ... )analysisData( set, outcomes, id_col = "id", time_col = NULL, value_cols = NULL, missing = c("none", "locf", "multiple"), imputer = NULL, ... )
set |
An |
outcomes |
Outcome data frame. |
id_col |
Participant-ID column in |
time_col |
Optional time column, required for LOCF. |
value_cols |
Columns subject to missing-data processing. Defaults to every non-ID/non-time column. |
missing |
One of |
imputer |
Explicit multiple-imputation callback. |
... |
Arguments forwarded to |
A filtered data frame, or a non-empty list of completed data frames for a multiple-imputation callback.
trial <- Trial("T1", c("A", "B")) p <- data.frame( id = c("p1", "p2"), arm = c("A", "B"), randomized = TRUE ) set <- intentionToTreat(trial, p) outcomes <- data.frame(id = c("p1", "p1", "p2"), time = c(0, 1, 0), value = c(NA, 2, 9)) analysisData(set, outcomes, time_col = "time", missing = "locf")trial <- Trial("T1", c("A", "B")) p <- data.frame( id = c("p1", "p2"), arm = c("A", "B"), randomized = TRUE ) set <- intentionToTreat(trial, p) outcomes <- data.frame(id = c("p1", "p1", "p2"), time = c(0, 1, 0), value = c(NA, 2, 9)) analysisData(set, outcomes, time_col = "time", missing = "locf")
Extract Analysis-Set Rows and Exclusions
analysisParticipants(x) analysisExclusions(x)analysisParticipants(x) analysisExclusions(x)
x |
An |
analysisParticipants() returns the included original rows;
analysisExclusions() returns one explicit exclusion row per excluded
source participant.
trial <- Trial("T1", c("A", "B")) p <- data.frame( id = c("p1", "screen"), arm = c("A", NA), randomized = c(TRUE, FALSE) ) x <- intentionToTreat(trial, p) analysisParticipants(x) analysisExclusions(x)trial <- Trial("T1", c("A", "B")) p <- data.frame( id = c("p1", "screen"), arm = c("A", NA), randomized = c(TRUE, FALSE) ) x <- intentionToTreat(trial, p) analysisParticipants(x) analysisExclusions(x)
Construct a Trial Arm
Arm( label, ratio = 1L, description = NA_character_, is_control = FALSE, treatment_code = NA_character_ )Arm( label, ratio = 1L, description = NA_character_, is_control = FALSE, treatment_code = NA_character_ )
label |
Non-empty arm label. |
ratio |
Positive integer allocation weight. |
description |
Optional description. |
is_control |
Whether this is a control arm. |
treatment_code |
Optional masked treatment code. |
An Arm object.
Arm("active", ratio = 2L, is_control = FALSE)Arm("active", ratio = 2L, is_control = FALSE)
Trial Arm
labelArm label.
ratioPositive integer allocation weight.
descriptionOptional description.
is_controlWhether this is a control arm.
treatment_codeOptional masked treatment code.
Arm Labels
arms(x) ## S4 method for signature 'Trial' arms(x)arms(x) ## S4 method for signature 'Trial' arms(x)
x |
A Trial object. |
Character vector of arm labels in allocation order.
arms(Trial("T1", c("active", "control")))arms(Trial("T1", c("active", "control")))
Revealed Assignments
assignments(seq) ## S4 method for signature 'RandomizationSequence' assignments(seq)assignments(seq) ## S4 method for signature 'RandomizationSequence' assignments(seq)
seq |
A RandomizationSequence object. |
Assignment table with every unrevealed arm replaced by NA.
sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) assignments(sequence)sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) assignments(sequence)
Randomization Audit Log
auditLog(x) ## S4 method for signature 'RandomizationSequence' auditLog(x)auditLog(x) ## S4 method for signature 'RandomizationSequence' auditLog(x)
x |
A RandomizationSequence object. |
Append-only audit data frame.
sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) auditLog(sequence)sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) auditLog(sequence)
Masked Treatment Codes
blindingCodes(manager)blindingCodes(manager)
manager |
A BlindingManager object. |
Named character vector mapping arms to masked codes.
manager <- blindingManager(Trial("T1", c("A", "B")), seed = 1) blindingCodes(manager)manager <- blindingManager(Trial("T1", c("A", "B")), seed = 1) blindingCodes(manager)
Computes Bang's arm-specific blinding index and normal-approximation
confidence interval. A guess matching the actual arm is correct;
dont_know is neutral; any other value, including an unknown arm label or
missing guess, is incorrect.
blindingIndex( guesses, arm_col = "arm", guess_col = "guess", dont_know = "dont_know", conf_level = 0.95 )blindingIndex( guesses, arm_col = "arm", guess_col = "guess", dont_know = "dont_know", conf_level = 0.95 )
guesses |
Data frame containing actual assignments and guesses. |
arm_col |
Name of the actual-assignment column. |
guess_col |
Name of the guess column. |
dont_know |
Sentinel used for a "don't know" response. |
conf_level |
Confidence level strictly between zero and one. |
A blinding_index object.
Bang H, Ni L, Davis CE (2004). Assessment of blinding in clinical trials. Controlled Clinical Trials, 25, 143-156.
guesses <- data.frame( arm = c("active", "active", "control", "control"), guess = c("active", "dont_know", "active", "control") ) blindingIndex(guesses)guesses <- data.frame( arm = c("active", "active", "control", "control"), guess = c("active", "dont_know", "active", "control") ) blindingIndex(guesses)
Construct a Blinding Manager
blindingManager(trial, sequence = NULL, codes = NULL, seed = NULL)blindingManager(trial, sequence = NULL, codes = NULL, seed = NULL)
trial |
A Trial object. |
sequence |
Optional RandomizationSequence object from the same trial. |
codes |
Optional named character vector mapping arms to masked treatment codes. |
seed |
Optional positive integer used to scramble generated codes. |
A BlindingManager object.
trial <- Trial("T1", c("active", "control")) blindingManager(trial, seed = 1)trial <- Trial("T1", c("active", "control")) blindingManager(trial, seed = 1)
Blinding and Treatment-Code Manager
trial_idTrial identifier.
armsOrdered arm labels.
code_mapNamed arm-to-code mapping.
kit_codesConcealed participant-level kit assignments.
unblinding_logAppend-only unblinding log.
fingerprintDeterministic semantic-content hash.
CONSORT Node Counts
consortCounts(x)consortCounts(x)
x |
A |
Node data frame used by the rendered diagram.
# See consortDiagram() for a complete flow example.# See consortDiagram() for a complete flow example.
Builds reconciled CONSORT participant counts and Graphviz DOT. DiagrammeR rendering is optional; the inspectable counts and DOT are always returned.
consortDiagram( trial, flow, render = requireNamespace("DiagrammeR", quietly = TRUE), show_reasons = TRUE )consortDiagram( trial, flow, render = requireNamespace("DiagrammeR", quietly = TRUE), show_reasons = TRUE )
trial |
A Trial object. |
flow |
One row per assessed participant using the documented flow schema. |
render |
Whether to create a |
show_reasons |
Whether exclusion/disposition reasons appear in labels. |
A consort_diagram object containing nodes, edges, reason counts,
DOT, and an optional widget.
Schulz KF, Altman DG, Moher D (2010). CONSORT 2010 Statement.
trial <- Trial("T1", c("active", "control")) flow <- data.frame( participant_id = c("p1", "p2", "p3"), eligible = c(TRUE, TRUE, FALSE), randomized = c(TRUE, TRUE, FALSE), arm = c("active", "control", NA), received_allocated = c(TRUE, TRUE, NA), followup_complete = c(TRUE, TRUE, NA), analysed = c(TRUE, TRUE, NA), pre_exclusion_reason = c(NA, NA, "ineligible"), not_received_reason = c(NA, NA, NA), followup_reason = c(NA, NA, NA), analysis_exclusion_reason = c(NA, NA, NA) ) consortDiagram(trial, flow, render = FALSE)trial <- Trial("T1", c("active", "control")) flow <- data.frame( participant_id = c("p1", "p2", "p3"), eligible = c(TRUE, TRUE, FALSE), randomized = c(TRUE, TRUE, FALSE), arm = c("active", "control", NA), received_allocated = c(TRUE, TRUE, NA), followup_complete = c(TRUE, TRUE, NA), analysed = c(TRUE, TRUE, NA), pre_exclusion_reason = c(NA, NA, "ineligible"), not_received_reason = c(NA, NA, NA), followup_reason = c(NA, NA, NA), analysis_exclusion_reason = c(NA, NA, NA) ) consortDiagram(trial, flow, render = FALSE)
Serializes metadata for the exact datasets in an SDTM-shaped or ADaM-shaped export. The result is a deterministic ODM metadata stub, not a submission-ready define.xml document.
defineXML( x, file = NULL, study_name = NULL, protocol_name = NULL, standard_version = NULL )defineXML( x, file = NULL, study_name = NULL, protocol_name = NULL, standard_version = NULL )
x |
An |
file |
Optional output path. Writing uses a temporary file followed by an atomic rename. |
study_name, protocol_name
|
Optional display metadata. |
standard_version |
Optional standard-version label. |
Invisibly, the XML string when file is NULL; otherwise the
normalized written path.
trial <- Trial("T1", c("A", "B")) participants <- data.frame(id = c("p1", "p2"), arm = c("A", "B")) xml <- defineXML(toSDTM(trial, participants)) grepl("ItemGroupDef", xml, fixed = TRUE)trial <- Trial("T1", c("A", "B")) participants <- data.frame(id = c("p1", "p2"), arm = c("A", "B")) xml <- defineXML(toSDTM(trial, participants)) grepl("ItemGroupDef", xml, fixed = TRUE)
Fits change-from-baseline or follow-up ANCOVA with treatment referenced to
an explicit control. Reported Cohen d values are unadjusted change-score
effects delegated to PhysioExperiment::cohensD() and are separate from the
adjusted ANCOVA estimate.
endpointANCOVA( data, followup, baseline, treatment, covariates = NULL, control = NULL, response_scale = c("change", "followup"), conf_level = 0.95 )endpointANCOVA( data, followup, baseline, treatment, covariates = NULL, control = NULL, response_scale = c("change", "followup"), conf_level = 0.95 )
data |
Participant-level endpoint data. |
followup, baseline, treatment
|
Scalar column names. |
covariates |
Optional additional model columns. |
control |
Control-arm label; defaults to the first observed arm. |
response_scale |
|
conf_level |
Confidence level for adjusted treatment estimates. |
An endpoint_analysis with standardized estimates, the lm fit,
complete analysis data, and missingness counts.
d <- data.frame( arm = rep(c("control", "active"), each = 4), baseline = rep(0:3, 2), followup = c(1, 2, 4, 5, 3, 4, 6, 7) ) endpointANCOVA(d, "followup", "baseline", "arm")d <- data.frame( arm = rep(c("control", "active"), each = 4), baseline = rep(0:3, 2), followup = c(1, 2, 4, 5, 3, 4, 6, 7) ) endpointANCOVA(d, "followup", "baseline", "arm")
Delegates longitudinal modelling and estimated marginal means to
PhysioClinStats. No alternate MMRM or complete-case ANCOVA fallback is
implemented here.
endpointMMRM( data, response, treatment, time, subject, baseline = NULL, covariates = NULL, control = NULL, target_time = NULL, covariance = c("unstructured", "ar1", "compound-symmetry", "toeplitz"), df = c("kenward-roger", "satterthwaite"), conf_level = 0.95 )endpointMMRM( data, response, treatment, time, subject, baseline = NULL, covariates = NULL, control = NULL, target_time = NULL, covariance = c("unstructured", "ar1", "compound-symmetry", "toeplitz"), df = c("kenward-roger", "satterthwaite"), conf_level = 0.95 )
data |
Longitudinal endpoint data. |
response, treatment, time, subject
|
Scalar column names. |
baseline |
Optional repeated subject-level baseline column. |
covariates |
Optional additional fixed-effect columns. |
control |
Control-arm label. |
target_time |
Optional one requested time level. |
covariance |
MMRM covariance structure. |
df |
Denominator degrees-of-freedom method. |
conf_level |
Confidence level. |
An endpoint_analysis carrying standardized treatment contrasts and
the underlying PhysioClinStats result objects.
From pilot data - a pair of numeric vectors, a data.frame with a
baseline and follow-up column, or a PhysioCohort cohortDesign()
plus column names - estimate to feed sampleSizeANCOVA().
estimateBaselineCorrelation( baseline, followup = NULL, cols = NULL, method = "pearson" )estimateBaselineCorrelation( baseline, followup = NULL, cols = NULL, method = "pearson" )
baseline |
A numeric vector of baseline values, a |
followup |
A numeric vector of follow-up values (when |
cols |
Length-2 character vector naming the baseline and follow-up
columns (when |
method |
Correlation method (default |
The estimated correlation (numeric).
Includes every randomized participant in the originally assigned arm. Missing outcomes, adherence, and post-randomization events do not alter membership.
intentionToTreat( trial, participants, id_col = "id", arm_col = "arm", randomized_col = "randomized" )intentionToTreat( trial, participants, id_col = "id", arm_col = "arm", randomized_col = "randomized" )
trial |
A Trial object. |
participants |
One row per source participant. |
id_col, arm_col, randomized_col
|
Column names in |
An analysis_set with included rows, member IDs, and explicit
exclusions.
trial <- Trial("T1", c("active", "control")) participants <- data.frame( id = c("p1", "p2", "screen"), arm = c("active", "control", NA), randomized = c(TRUE, TRUE, FALSE) ) intentionToTreat(trial, participants)trial <- Trial("T1", c("active", "control")) participants <- data.frame( id = c("p1", "p2", "screen"), arm = c("active", "control", NA), randomized = c(TRUE, TRUE, FALSE) ) intentionToTreat(trial, participants)
Reveal the Next Allocation
nextAllocation(seq, requester = NA_character_) ## S4 method for signature 'RandomizationSequence' nextAllocation(seq, requester = NA_character_)nextAllocation(seq, requester = NA_character_) ## S4 method for signature 'RandomizationSequence' nextAllocation(seq, requester = NA_character_)
seq |
A RandomizationSequence object. |
requester |
Optional audit identity. |
A list containing participant_id, arm, and the modified
sequence.
sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) nextAllocation(sequence, requester = "site")sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) nextAllocation(sequence, requester = "site")
Construct a Trial Participant
Participant( id, strata = character(0), arm = NA_character_, enrolled_at = NA_character_ )Participant( id, strata = character(0), arm = NA_character_, enrolled_at = NA_character_ )
id |
Non-empty participant identifier. |
strata |
Named character vector mapping prognostic factors to levels. |
arm |
Allocated arm, or |
enrolled_at |
Optional enrollment time representation. |
A Participant object.
Participant("P001", strata = c(site = "north"))Participant("P001", strata = c(site = "north"))
Trial Participant
idParticipant identifier.
strataNamed character vector of prognostic-factor levels.
armAllocated arm, or NA before allocation.
enrolled_atOptional enrollment time representation.
Starts from ITT and excludes participants with a major protocol deviation or caller-selected nonadherence/incompletion flags. Multiple exclusion reasons are retained in a deterministic order.
perProtocol( trial, participants, deviations = NULL, id_col = "id", arm_col = "arm", randomized_col = "randomized", deviation_id_col = "participant_id", major_col = "major", code_col = "code", adherent_col = NULL, completed_col = NULL )perProtocol( trial, participants, deviations = NULL, id_col = "id", arm_col = "arm", randomized_col = "randomized", deviation_id_col = "participant_id", major_col = "major", code_col = "code", adherent_col = NULL, completed_col = NULL )
trial |
A Trial object. |
participants |
One row per source participant. |
deviations |
Optional protocol-deviation data frame. |
id_col, arm_col, randomized_col
|
Column names in |
deviation_id_col, major_col, code_col
|
Columns in |
adherent_col, completed_col
|
Optional logical columns in
|
A PP analysis_set.
trial <- Trial("T1", c("active", "control")) participants <- data.frame( id = c("p1", "p2", "screen"), arm = c("active", "control", NA), randomized = c(TRUE, TRUE, FALSE), adherent = c(TRUE, FALSE, NA) ) perProtocol(trial, participants, adherent_col = "adherent")trial <- Trial("T1", c("active", "control")) participants <- data.frame( id = c("p1", "p2", "screen"), arm = c("active", "control", NA), randomized = c(TRUE, TRUE, FALSE), adherent = c(TRUE, FALSE, NA) ) perProtocol(trial, participants, adherent_col = "adherent")
Power of a two-arm binary endpoint at a given sample size
powerBinary(n1, p1, p2, sig_level = 0.05, ratio = 1, sides = 2L)powerBinary(n1, p1, p2, sig_level = 0.05, ratio = 1, sides = 2L)
n1 |
Control-arm sample size. |
p1, p2, sig_level, ratio, sides
|
As in |
The achieved power.
Power of a two-arm continuous endpoint at a given sample size
powerContinuous(n1, delta, sd, sig_level = 0.05, ratio = 1, sides = 2L)powerContinuous(n1, delta, sd, sig_level = 0.05, ratio = 1, sides = 2L)
n1 |
Control-arm sample size. |
delta, sd, sig_level, ratio, sides
|
As in |
The achieved power (numeric in 0-1).
sampleSizeContinuous(), powerCurve()
powerContinuous(64, delta = 5, sd = 10) # ~0.80powerContinuous(64, delta = 5, sd = 10) # ~0.80
Power curve over a range of sample sizes or effect sizes
powerCurve( delta, sd, n1 = NULL, deltas = NULL, sig_level = 0.05, ratio = 1, sides = 2L )powerCurve( delta, sd, n1 = NULL, deltas = NULL, sig_level = 0.05, ratio = 1, sides = 2L )
delta, sd, sig_level, ratio, sides
|
As in |
n1 |
A vector of control-arm sizes to evaluate (vary n at fixed effect),
or |
deltas |
A vector of effect differences to evaluate at fixed |
A data.frame with columns n1, delta, power.
powerCurve(delta = 5, sd = 10, n1 = seq(20, 120, 10))powerCurve(delta = 5, sd = 10, n1 = seq(20, 120, 10))
The full allocation table is stored internally. Public accessors mask all rows after the reveal pointer.
trial_idTrial identifier.
methodAllocation method.
armsOrdered arm labels.
ratioNamed allocation weights.
seedCaptured random seed.
strataTrial stratification definition.
block_sizesAdmissible block lengths.
p_biasMinimization biased-coin probability.
weightsNamed minimization factor weights.
imbalanceMinimization discrepancy measure.
tableSealed allocation table.
auditAppend-only access audit.
fingerprintDeterministic semantic-content hash.
revealedNumber of revealed rows.
Generate a Concealed Randomization Sequence
randomize( trial, method = c("simple", "permuted_block", "stratified_block", "minimization"), n = NULL, participants = NULL, block_sizes = NULL, seed = NULL, p_bias = 0.8, weights = NULL, imbalance = c("range", "variance", "sd"), requester = NA_character_ )randomize( trial, method = c("simple", "permuted_block", "stratified_block", "minimization"), n = NULL, participants = NULL, block_sizes = NULL, seed = NULL, p_bias = 0.8, weights = NULL, imbalance = c("range", "variance", "sd"), requester = NA_character_ )
trial |
A Trial object. |
method |
Allocation method. Simple randomization matches the allocation ratio only in expectation. Block methods enforce the ratio in every completed block. |
n |
Number of anonymous slots. Valid only for an unstratified trial and the simple or permuted-block methods. |
participants |
A data frame with |
block_sizes |
Positive block lengths, each a multiple of the allocation weight sum. |
seed |
Positive integer seed. If |
p_bias |
High-probability branch of minimization's biased coin. |
weights |
Optional named prognostic-factor weights. |
imbalance |
Pocock-Simon discrepancy measure. |
requester |
Optional audit identity recorded at sealing. |
A concealed RandomizationSequence object.
trial <- Trial("T1", c("active", "control")) randomize(trial, "permuted_block", n = 8, seed = 2026)trial <- Trial("T1", c("active", "control")) randomize(trial, "permuted_block", n = 8, seed = 2026)
Captured Randomization Seed
randomSeed(seq) ## S4 method for signature 'RandomizationSequence' randomSeed(seq)randomSeed(seq) ## S4 method for signature 'RandomizationSequence' randomSeed(seq)
seq |
A RandomizationSequence object. |
Positive integer seed.
sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 19) randomSeed(sequence)sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 19) randomSeed(sequence)
Delegates each subject's dual-threshold classification to
PhysioClinical::classifyResponder() and summarizes true responders with
Wilson score intervals. Missing outcomes remain explicit and are excluded
from the rate denominator.
responderAnalysis( data, baseline, followup, treatment, mdc, mcid, direction = c("increase", "decrease"), control = NULL, conf_level = 0.95 )responderAnalysis( data, baseline, followup, treatment, mdc, mcid, direction = c("increase", "decrease"), control = NULL, conf_level = 0.95 )
data |
Participant-level data. |
baseline, followup, treatment
|
Scalar column names. |
mdc, mcid
|
Positive MDC and MCID thresholds. |
direction |
Whether improvement is an increase or decrease. |
control |
Optional control arm placed first. |
conf_level |
Wilson interval confidence level. |
A responder_analysis with subject classifications and arm
summaries.
The recommended pre-post rehabilitation analysis: adjusting the follow-up
outcome for its baseline reduces the residual variance by a factor
, where is the baseline-outcome correlation -
shrinking the required sample versus an unadjusted comparison.
sampleSizeANCOVA( delta, sd, baseline_cor, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )sampleSizeANCOVA( delta, sd, baseline_cor, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )
delta, sd, power, sig_level, ratio, sides, dropout, cluster_size, icc
|
As in
|
baseline_cor |
Correlation |
A trial_power object.
Frison & Pocock (1992), Stat Med; Borm et al. (2007), J Clin Epi.
sampleSizeChangeScore(), estimateBaselineCorrelation()
sampleSizeANCOVA(delta = 5, sd = 10, baseline_cor = 0.6) # < 64/armsampleSizeANCOVA(delta = 5, sd = 10, baseline_cor = 0.6) # < 64/arm
Comparison of two proportions (e.g. responder rates), via the normal
approximation with unequal allocation; matches stats::power.prop.test
in the balanced case.
sampleSizeBinary( p1, p2, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )sampleSizeBinary( p1, p2, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )
p1 |
Control-arm proportion. |
p2 |
Treatment-arm proportion. |
power, sig_level, ratio, sides, dropout, cluster_size, icc
|
As in
|
A trial_power object.
sampleSizeContinuous(), powerBinary()
sampleSizeBinary(p1 = 0.30, p2 = 0.50) # responder-rate 30% vs 50%sampleSizeBinary(p1 = 0.30, p2 = 0.50) # responder-rate 30% vs 50%
Analysis of the change score (follow-up minus baseline). The change SD is
; change-score analysis beats an unadjusted
follow-up comparison only when , and is never better than
ANCOVA.
sampleSizeChangeScore( delta, sd, baseline_cor, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )sampleSizeChangeScore( delta, sd, baseline_cor, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )
delta, sd, baseline_cor, power, sig_level, ratio, sides, dropout, cluster_size, icc
|
As in |
A trial_power object.
Two-sample comparison of means. Delegates the balanced case's core to the
noncentral-t (matching stats::power.t.test) and adds unequal
allocation, cluster design effect, and dropout inflation.
sampleSizeContinuous( delta, sd, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )sampleSizeContinuous( delta, sd, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )
delta |
Target difference in means (treatment - control). |
sd |
Common (residual) standard deviation of the endpoint. |
power |
Target power (default 0.8). |
sig_level |
Two-sided (or one-sided, see |
ratio |
Allocation ratio n2/n1 (treatment/control; default 1). |
sides |
1 or 2 (default 2). |
dropout |
Expected proportion lost to follow-up; inflates enrolment (default 0). |
cluster_size |
Average subjects per cluster for a cluster-randomized
design ( |
icc |
Intra-cluster correlation (required with |
A trial_power object (n1, n2, n_total,
n_enrolled, design effect, clusters, ...).
sampleSizeANCOVA(), sampleSizeBinary(), powerContinuous()
sampleSizeContinuous(delta = 5, sd = 10) # d = 0.5 -> 64/arm sampleSizeContinuous(delta = 5, sd = 10, dropout = 0.2)sampleSizeContinuous(delta = 5, sd = 10) # d = 0.5 -> 64/arm sampleSizeContinuous(delta = 5, sd = 10, dropout = 0.2)
Comparison of the mean of n_measurements post-baseline measurements
under a compound-symmetry correlation correlation between them. The
effective variance is , so more visits help
most when the within-subject correlation is low.
sampleSizeRepeatedMeasures( delta, sd, n_measurements, correlation, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )sampleSizeRepeatedMeasures( delta, sd, n_measurements, correlation, power = 0.8, sig_level = 0.05, ratio = 1, sides = 2L, dropout = 0, cluster_size = NULL, icc = NULL )
delta, sd, power, sig_level, ratio, sides, dropout, cluster_size, icc
|
As in
|
n_measurements |
Number of post-baseline measurements per subject. |
correlation |
Compound-symmetry correlation between measurements (0-1). |
A trial_power object.
Frison & Pocock (1992), Stat Med.
Marks protocol evidence against the bundled SPIRIT 2013 checklist. This is a completeness aid and does not certify protocol compliance.
spiritChecklist(protocol, checklist = NULL)spiritChecklist(protocol, checklist = NULL)
protocol |
Named list ( |
checklist |
Optional replacement checklist using the bundled schema. |
A spirit_checklist data frame with completion flags and evidence.
Chan AW et al. (2013). SPIRIT 2013 Statement.
spiritChecklist(list(`1` = "Descriptive title", `2` = "Registry ID"))spiritChecklist(list(`1` = "Descriptive title", `2` = "Registry ID"))
Converts a validated long schedule into a deterministic wide enrolment/intervention/assessment table.
spiritSchedule(trial, events, marker = "X")spiritSchedule(trial, events, marker = "X")
trial |
A Trial object. |
events |
Long schedule data frame using the documented event schema. |
marker |
Default marker for scheduled cells. |
A spirit_schedule object with validated long events, a wide table,
and ordered timepoint metadata.
Chan AW et al. (2013). SPIRIT 2013 Statement.
trial <- Trial("T1", c("active", "control")) events <- data.frame( timepoint_id = c("screen", "week12"), timepoint_label = c("Screening", "Week 12"), timepoint_order = c(-1L, 1L), category = c("enrolment", "assessment"), activity = c("Eligibility", "Primary endpoint"), arm = NA_character_, scheduled = TRUE ) spiritSchedule(trial, events)trial <- Trial("T1", c("active", "control")) events <- data.frame( timepoint_id = c("screen", "week12"), timepoint_label = c("Screening", "Week 12"), timepoint_order = c(-1L, 1L), category = c("enrolment", "assessment"), activity = c("Eligibility", "Primary endpoint"), arm = NA_character_, scheduled = TRUE ) spiritSchedule(trial, events)
Trial Strata
strata(x) ## S4 method for signature 'Trial' strata(x)strata(x) ## S4 method for signature 'Trial' strata(x)
x |
A Trial object. |
Named list of prognostic factors and admissible levels.
strata(Trial( "T1", c("active", "control"), strata = list(site = c("north", "south")) ))strata(Trial( "T1", c("active", "control"), strata = list(site = c("north", "south")) ))
Builds an ADSL population table and a generic BDS analysis table from explicit analysis sets. This structural export is not a claim of formal ADaM conformance.
toADaM( set, subject_data, bds = NULL, study_id = set$trial_id, id_col = "id", treatment_col = "arm", population_flags = NULL )toADaM( set, subject_data, bds = NULL, study_id = set$trial_id, id_col = "id", treatment_col = "arm", population_flags = NULL )
set |
The authoritative primary |
subject_data |
One row per source participant. |
bds |
Optional generic BDS source data frame. A named list may contain
an |
study_id |
Non-empty study identifier. |
id_col, treatment_col
|
Subject ID and originally assigned treatment columns. |
population_flags |
Optional named list of other |
An adam_export containing datasets, manifest, and population
metadata.
trial <- Trial("T1", c("active", "control")) subjects <- data.frame( id = c("p1", "p2", "screen"), arm = c("active", "control", NA), randomized = c(TRUE, TRUE, FALSE) ) itt <- intentionToTreat(trial, subjects) export <- toADaM(itt, subjects) export$datasets$ADSLtrial <- Trial("T1", c("active", "control")) subjects <- data.frame( id = c("p1", "p2", "screen"), arm = c("active", "control", NA), randomized = c(TRUE, TRUE, FALSE) ) itt <- intentionToTreat(trial, subjects) export <- toADaM(itt, subjects) export$datasets$ADSL
Builds deterministic, linked trial domains with explicit sponsor mappings. The output is structurally SDTM-shaped; it is not a claim of CDISC, regulator, or third-party validator conformance.
toSDTM( trial, participants, adverse_events = NULL, findings = list(), study_id = trial@id, id_col = "id", arm_col = "arm", sex_col = NULL, birth_date_col = NULL, reference_start_col = NULL, reference_end_col = NULL, country_col = NULL, site_col = NULL, extra_domains = list() )toSDTM( trial, participants, adverse_events = NULL, findings = list(), study_id = trial@id, id_col = "id", arm_col = "arm", sex_col = NULL, birth_date_col = NULL, reference_start_col = NULL, reference_end_col = NULL, country_col = NULL, site_col = NULL, extra_domains = list() )
trial |
A Trial object. |
participants |
One row per screened or enrolled participant. |
adverse_events |
Optional adverse events accepted by |
findings |
Named list containing normalized |
study_id |
Non-empty study identifier. |
id_col, arm_col
|
Participant ID and assigned-arm columns. |
sex_col, birth_date_col, reference_start_col, reference_end_col
|
Optional participant columns. |
country_col, site_col
|
Optional country and site columns. |
extra_domains |
Named list of already constructed two-letter domains,
such as output from |
An sdtm_export containing datasets, manifest, and mapping metadata.
trial <- Trial("T1", c("active", "control")) participants <- data.frame( id = c("p1", "p2"), arm = c("active", "control") ) export <- toSDTM(trial, participants) export$datasets$DMtrial <- Trial("T1", c("active", "control")) participants <- data.frame( id = c("p1", "p2"), arm = c("active", "control") ) export <- toSDTM(trial, participants) export$datasets$DM
Construct a Randomized Trial
Trial( id, arms, allocation_ratio = NULL, strata = list(), endpoints = list(), metadata = list() )Trial( id, arms, allocation_ratio = NULL, strata = list(), endpoints = list(), metadata = list() )
id |
Non-empty trial identifier. |
arms |
Character arm labels or a list of Arm objects. |
allocation_ratio |
Optional named or positional allocation weights. |
strata |
Named list mapping prognostic factors to admissible levels. |
endpoints |
Named endpoint definitions. |
metadata |
Free-form trial metadata. |
A Trial object.
Trial( "rehab-01", arms = c("active", "control"), strata = list(site = c("north", "south")) )Trial( "rehab-01", arms = c("active", "control"), strata = list(site = c("north", "south")) )
Randomized Trial Definition
idTrial identifier.
armsOrdered arm labels.
arm_specsArm definitions.
allocation_ratioNamed integer allocation weights.
strataNamed list of prognostic factors and admissible levels.
endpointsEndpoint definitions carried by the trial.
metadataFree-form trial metadata.
Trial Object Fingerprint
trialFingerprint(x) ## S4 method for signature 'RandomizationSequence' trialFingerprint(x) ## S4 method for signature 'BlindingManager' trialFingerprint(x)trialFingerprint(x) ## S4 method for signature 'RandomizationSequence' trialFingerprint(x) ## S4 method for signature 'BlindingManager' trialFingerprint(x)
x |
A RandomizationSequence or BlindingManager object. |
Deterministic xxhash64 semantic-content fingerprint.
sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) trialFingerprint(sequence)sequence <- randomize(Trial("T1", c("A", "B")), n = 4, seed = 1) trialFingerprint(sequence)
Record an Unblinding Event
unblind( manager, participant_id, requester = NA_character_, reason = NA_character_ )unblind( manager, participant_id, requester = NA_character_, reason = NA_character_ )
manager |
A BlindingManager object. |
participant_id |
Participant to unblind. |
requester |
Optional identity requesting unblinding. |
reason |
Optional reason for unblinding. |
The modified BlindingManager object.
trial <- Trial("T1", c("A", "B")) sequence <- randomize(trial, n = 4, seed = 1) manager <- blindingManager(trial, sequence, seed = 2) unblind(manager, "slot_1", requester = "PI", reason = "safety")trial <- Trial("T1", c("A", "B")) sequence <- randomize(trial, n = 4, seed = 1) manager <- blindingManager(trial, sequence, seed = 2) unblind(manager, "slot_1", requester = "PI", reason = "safety")
Unblinding Log
unblindingLog(manager)unblindingLog(manager)
manager |
A BlindingManager object. |
Append-only unblinding data frame.
manager <- blindingManager(Trial("T1", c("A", "B")), seed = 1) unblindingLog(manager)manager <- blindingManager(Trial("T1", c("A", "B")), seed = 1) unblindingLog(manager)
Checks the documented structural contract for exports created by
toSDTM() or toADaM(). A clean report does not mean an external
conformance product or regulator has accepted the data.
validateCDISC(x, controlled_terms = NULL)validateCDISC(x, controlled_terms = NULL)
x |
An |
controlled_terms |
Optional named list, or a data frame with
|
A cdisc_validation object with deterministic issues and summary.
trial <- Trial("T1", c("A", "B")) participants <- data.frame(id = c("p1", "p2"), arm = c("A", "B")) validateCDISC(toSDTM(trial, participants))trial <- Trial("T1", c("A", "B")) participants <- data.frame(id = c("p1", "p2"), arm = c("A", "B")) validateCDISC(toSDTM(trial, participants))