From Protocol Text to an Executable Sequence
A MAMS protocol describes a sequence of actions: assign participants, analyze data at planned stages, apply interim rules, and reach final decisions. A simulation must reproduce that sequence for every replicate. The task here is not to generate outcomes or calculate an analysis statistic from raw data. It is to make the protocol’s stated allocation, analysis timing, decision rules, and final conclusions explicit enough that each simulated replicate is processed in the intended order.
A useful translation treats a trial replicate as a sequence of states. At each planned analysis, the algorithm receives the data snapshot that the protocol says is available, evaluates the specified rules for unresolved treatment arms, updates which arms remain active, and records decisions. This separation makes it easier to check that the simulation follows the protocol rather than an informal recollection of it.
Before applying such an algorithm, assume the protocol is sufficiently specified to determine what happens at every planned decision point. In particular, it must state the treatment arms and control, allocation scheme, analysis stages, data available at each stage, analysis measure and direction, interim boundaries, final decision rule, and what happens when the trial or an arm stops early. If any of these are ambiguous, the simulation cannot resolve the ambiguity statistically; it needs a documented design decision first.
The procedure also assumes that each stage input represents the data permitted by the protocol at that analysis. For example, an analysis at a planned look must not silently include outcomes that the protocol would not yet have available. Data generation, allocation implementation, and the construction of interim snapshots are separate tasks. Here they are treated as specified inputs to the decision sequence.
Specify the Inputs, State, and Outputs
Write down the inputs before writing the sequence. At the design level, these include the number and labels of treatment arms, the control arm, allocation ratios, planned stages, and the rules that govern analysis and stopping. At the replicate level, the algorithm receives the stage-specific information needed to evaluate those rules: for example, an analysis statistic or an already calculated comparison for each eligible arm.
The state must distinguish arms that have not yet been evaluated, arms that remain active, and arms with a terminal decision. An arm that crosses an efficacy boundary is not the same as an arm that remains active for another stage; likewise, a futile arm is not eligible for later analyses unless the protocol explicitly says otherwise. Make these states explicit rather than inferring them from scattered conditional statements.
For clarity, define an analysis statistic \(Z_{j,k}\) for treatment arm \(j\) at stage \(k\), where larger values favor treatment. This notation is only an example of how to name the statistic: a real algorithm must use the measure and direction stated in its protocol. The statistic may already incorporate the protocol’s chosen control comparison and analysis method. Do not replace it with a different statistic simply because that is more convenient to compute.
A replicate should return a structured record, not just a final label. Useful fields include the stage reached, the arms active at each analysis, the decision for each arm, whether the trial stopped early, and any final treatment-success indicators. These records allow a reviewer to compare what the algorithm did with the rule that was supposed to trigger each action.
Order the Decisions Before Coding Them
A protocol’s rules can interact. If an arm meets an efficacy rule at a stage, it may no longer be tested for futility at that same stage; if all arms become terminal, there is no later analysis to perform. Therefore, specify the order of checks, not just the collection of boundaries. The following sequence is a general framework, not a substitute for the protocol’s exact rules.
Set the active-arm set to the treatment arms not yet resolved. Create an empty decision record and identify the planned stage sequence.
Use only the analysis results that the protocol makes available at this look. Confirm that each result corresponds to the correct arm, stage, endpoint, and comparison.
For each arm eligible at this look, check the protocol’s efficacy, futility, or continuation conditions, including the exact treatment of boundary equality.
Record decisions, remove terminal arms from future analyses, and apply any protocol-level stopping condition. Continue only if another planned analysis is required.
At the terminal stage, apply the final rule to arms that remain eligible, record all final decisions, and return the replicate-level outputs.
A compact formal representation helps expose omissions. Let \(A_k\) be the set of arms eligible for evaluation at stage \(k\), and let \(D_{j,k}\) be the decision for arm \(j\) at that stage. The state update is determined by the protocol’s decision function \(g_k\):
This notation does not imply that every protocol uses a single statistic or identical rules at every stage. It emphasizes that the active set at the next look depends on the decisions made at the current look. The stopping rule must also be explicit: for example, the trial might stop when no treatment arms remain active, or it might continue to collect control information for another purpose. Use the protocol’s condition, not a default assumption.
Worked Example: Translating a Two-Stage Protocol
Worked Example: Translating a Two-Stage Protocol
Hypothetical protocol. There are three experimental arms, A, B, and C, and a shared control. The protocol plans an interim analysis after stage 1 and a final analysis after stage 2. For each experimental arm, the protocol supplies a standardized statistic \(Z_{j,k}\), with larger values favoring that treatment. At stage 1, declare an arm successful if \(Z_{j,1}\geq 2.80\); stop an arm for futility if \(Z_{j,1}<0.50\); otherwise continue it. At stage 2, declare an arm successful if \(Z_{j,2}\geq 1.98\); otherwise record no success for that arm. The trial stops when all three arms have a terminal decision.
Inputs and initial state. The design inputs are the three treatment labels, shared control, two analysis stages, and the two sets of rules above. For this worked replicate, assume the protocol’s allocation and stage-data procedures have supplied these statistics: at stage 1, \(Z_{A,1}=2.91\), \(Z_{B,1}=0.32\), and \(Z_{C,1}=1.40\). Initially, \(A_1=\{A,B,C\}\).
Apply stage 1 in rule order. Arm A meets the efficacy condition because \(2.91\geq2.80\), so record “success at stage 1” and make A terminal. Arm B meets the futility condition because \(0.32<0.50\), so record “stop for futility” and make B terminal. Arm C meets neither terminal condition: \(1.40<2.80\) and \(1.40\not<0.50\). Record “continue” for C. Thus \(A_2=\{C\}\). The trial has not stopped because one arm remains active.
At stage 2, suppose the supplied statistic for C is \(Z_{C,2}=2.03\). Since \(2.03\geq1.98\), record “success at final analysis” for C. There are now no active arms, so the replicate terminates.
Output for this replicate. The record contains A successful at stage 1, B stopped for futility at stage 1, and C successful at stage 2. It also records that the trial reached stage 2 and that all arms were resolved by that analysis. The example does not calculate the statistics from outcomes; it demonstrates how the protocol maps stage inputs to actions.
Boundary Conditions and a Short Justification
A boundary is part of the rule, not a cosmetic detail. “At least 2.80” means equality satisfies the condition; “greater than 2.80” does not. Similarly, a futility rule written as \(Z<0.50\) does not include \(Z=0.50\). The algorithm should encode the comparison exactly as written and should use the protocol’s stated numerical precision. Rounding a statistic before comparison can change a decision close to a boundary.
The decision sequence is justified by the meaning of the protocol: an arm can receive a terminal decision only at an analysis where it is eligible, and a terminal arm cannot be treated as active at a later look unless the protocol explicitly permits re-entry. Therefore, the active set must be updated after each look and before the next one. Applying all stage rules to all arms at the end would ignore the timing and selection created by the interim decisions.
The inclusion follows because the next active set contains only arms that were active at stage \(k\) and received a continuation decision. It is a useful invariant for a software check: if an arm disappears and later reappears without an explicit protocol provision, the state transition is wrong.
Worked Example: Testing Equality and the Stopping Condition
Worked Example: Testing Equality and the Stopping Condition
Use the same hypothetical protocol, but suppose the stage 1 inputs are \(Z_{A,1}=2.80\), \(Z_{B,1}=0.50\), and \(Z_{C,1}=0.49\). Apply the written inequalities literally.
For A, \(2.80\geq2.80\), so A is successful at stage 1. For B, \(0.50\) is not less than \(0.50\), and it is also less than \(2.80\); therefore B continues. For C, \(0.49<0.50\), so C stops for futility. The resulting active set is \(A_2=\{B\}\), and the trial continues because B is unresolved.
Suppose the stage 2 statistic for B is \(Z_{B,2}=1.98\). The final condition is \(Z_{B,2}\geq1.98\), so B is successful at the final analysis. The replicate reaches stage 2 and then terminates. If instead B had received a stage 2 statistic of \(1.97\), it would have been recorded as no success; the trial would still terminate because stage 2 is the final planned analysis.
This test checks three distinct implementation details: equality at the interim efficacy boundary, equality at the interim futility boundary, and equality at the final boundary. A program that uses one generic “crossed boundary” comparison for all three conditions could produce a different answer.
From Replicate Decisions to Recorded Outcomes
A simulation algorithm should distinguish the decisions inside one replicate from summaries across many replicates. For a particular treatment arm, define an indicator \(I_r\) to equal 1 if the arm meets a specified event in replicate \(r\), and 0 otherwise. The event must be stated precisely, such as “declared successful at any stage.” If the event is recorded for each replicate, its average over \(R\) replicates is the simulated proportion of replicates in which that event occurred:
The logic is direct: each replicate contributes one when the event occurs and zero otherwise, so the sum counts event occurrences; division by \(R\) gives their proportion. This is why a clear replicate-level record matters. If “success at an interim look” and “success at the final analysis” are collapsed into one ambiguous label, the simulation cannot reliably summarize stage-specific events later.
Worked Example: Checking a Replicate Record
Worked Example: Checking a Replicate Record
Consider five hypothetical replicates for treatment A. The protocol-level event of interest is “A is declared successful at any stage.” Suppose the decision records show: success at stage 1; no success; success at stage 2; stopped for futility; success at stage 1.
Assign the event indicator in order: \(I_1=1\), \(I_2=0\), \(I_3=1\), \(I_4=0\), and \(I_5=1\). Then
Thus the event occurred in 3 of the 5 hypothetical replicates, giving a simulated proportion of 0.600. This calculation depends on the recorded decisions being faithful to the protocol; it does not repair a wrongly translated interim rule.
Diagnostics, Alternatives, and Limitations
A protocol translation should be checked before relying on simulation results. Useful checks include the following:
- Boundary tests: test values just below, exactly at, and just above every boundary.
- State checks: confirm that terminal arms never return to the active set, and that no decision is assigned at a stage an arm did not reach.
- Stopping checks: confirm the trial stops exactly under the stated condition and no later analysis is performed after termination.
- Input checks: confirm every statistic is associated with the correct arm, stage, endpoint, and comparison, and that all required inputs are present.
- Audit checks: retain enough information to trace each decision to the rule and value that triggered it.
If a required input is missing or an analysis cannot be performed, the algorithm must follow a protocol-specified contingency. It should not silently treat the value as zero, carry forward an earlier statistic, or invent a decision. Likewise, a decision rule that depends on a quantity not supplied at that stage indicates a mismatch between the protocol specification and the simulation inputs.
A protocol-driven state sequence is generally easier to audit than ad hoc code that mixes data handling, stage eligibility, and decision rules in one block. A table of rules can also be useful for reviewing boundaries, but it does not by itself enforce the order of actions or stopping. Conversely, a generic state-machine template is not enough if its rule conditions are not filled in exactly from the protocol. The appropriate approach is to preserve the protocol’s wording in a decision table and implement that table as an ordered state update.
The translation has limits. It cannot establish that the outcome model is appropriate, that the allocation mechanism was simulated correctly, or that the analysis statistic is valid. Nor can it decide an ambiguous protocol on statistical grounds. It provides a disciplined mapping from specified stage inputs to protocol actions; each other component of the simulation needs its own specification and validation.
Common Mistakes
- Evaluating every arm at every stage. This ignores interim removal. Evaluate only arms eligible under the current state.
- Using an intuitive rather than literal boundary. “At least” includes equality; “greater than” excludes it. Encode the stated inequality.
- Confusing an arm stop with a trial stop. A single arm can stop while other arms continue. Define and apply both arm-level and trial-level conditions.
- Changing the analysis input while translating the rule. The decision logic must use the protocol’s specified analysis and comparison, not a convenient substitute.
- Recording only an overall result. Without stage and arm decisions, it is difficult to audit the sequence or summarize stage-specific events.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions below.
- A protocol says to stop an arm for futility when \(Z<0.40\). What decision follows when \(Z=0.40\), assuming the efficacy condition is not met?
- At an interim analysis, arms A and B continue and arm C is declared futile. What should the active set contain at the next stage?
- Why is it not enough for a simulation to return only “trial success” or “trial failure” for each replicate?
- In 200 hypothetical replicates, an arm meets the specified success event in 46. Write the replicate-average estimate of the event proportion.
- A stage 2 rule needs a statistic that is absent from the replicate input. Should the algorithm substitute the stage 1 value? Explain.
Solutions. (1) The arm continues, because \(0.40\not<0.40\); the protocol’s strict inequality excludes equality. (2) The next active set is \(\{A,B\}\); C is terminal and must not be evaluated later unless the protocol expressly allows re-entry. (3) An overall label loses which arm was successful, at what stage a decision occurred, and whether an arm stopped for futility. Those details are needed to audit the rules and define stage-specific events. (4) The estimate is \(46/200=0.230\), or 23.0% of the hypothetical replicates. (5) No. Carrying forward the stage 1 statistic would invent an input and change the protocol. The algorithm must use a specified contingency or flag the replicate as not evaluable under the stated procedure.