  In clinical trials, response-adaptive randomization (RAR) has the appealing
ability to assign more subjects to better-performing treatments based on
interim results. The traditional RAR strategy alters the randomization ratio on
a patient-by-patient basis; this has been heavily criticized for bias due to
time-trends. An alternate approach is blocked RAR, which groups patients
together in blocks and recomputes the randomization ratio in a block-wise
fashion; the final analysis is then stratified by block. However, the typical
blocked RAR design divides patients into equal-sized blocks, which is not
generally optimal.
  This paper presents TrialMDP, an algorithm that designs two-armed blocked RAR
clinical trials. Our method differs from past approaches in that it optimizes
the size and number of blocks as well as their treatment allocations. That is,
the algorithm yields a policy that adaptively chooses the size and composition
of the next block, based on results seen up to that point in the trial.
TrialMDP is related to past works that compute optimal trial designs via
dynamic programming.
  The algorithm maximizes a utility function balancing (i) statistical power,
(ii) patient outcomes, and (iii) the number of blocks. We show that it attains
significant improvements in utility over a suite of baseline designs, and gives
useful control over the tradeoff between statistical power and patient
outcomes. It is well suited for small trials that assign high cost to failures.
  We provide TrialMDP as an R package on GitHub:
https://github.com/dpmerrell/TrialMDP
