Configuration¶
All study parameters are defined in a YAML configuration file (config.yaml
by default). The file path can be overridden with the URAND_CONFIG_FILE
environment variable.
Study Definition¶
Each study is defined as a top-level key in the YAML file:
"My Clinical Trial":
starting_seed: 100
target_enrollment: 200
treatments:
- Treatment A
- Treatment B
- Placebo
factors:
site:
["Site 1", "Site 2", "Site 3"]
age_group:
["18-40", "41-65", "65+"]
sex:
["Male", "Female"]
disease_severity:
["Mild", "Moderate", "Severe"]
Parameter Reference¶
Parameter |
Default |
Description |
|---|---|---|
|
(required) |
List of treatment arm names. |
|
(required) |
Dictionary of prognostic factor names to their possible levels. |
|
(required) |
Seed for the NumPy PCG64 random number generator. Ensures reproducibility. |
|
|
Initial number of balls per treatment in each urn. |
|
|
Number of balls added for the assigned treatment after each draw. |
|
|
Number of balls added for unassigned treatments after each draw. |
|
|
Imbalance measure. Options: |
|
|
Method for selecting among strata urns. |
|
none |
Optional total planned enrollment target. Enables the enrollment progress bar in the web dashboard. |
Database¶
The database connection string is set at the top level of the config file:
db: sqlite:///urn-randomization.db
Any SQLAlchemy-compatible connection string is accepted.
Environment Variables¶
Variable |
Description |
|---|---|
|
Path to the YAML config file (overrides default |
|
Name of the study to load (must match a top-level key in the config). |
|
Secret key for Flask session signing. |
|
Google OAuth 2.0 client ID. |
|
Google OAuth 2.0 client secret. |
|
Set to |
How Urn Randomization Works¶
The urn randomization scheme (Wei, 1978) maintains a set of urns — one per
factor-level pair (e.g., one urn for sex=Male, another for age_group=65+).
Each urn contains colored balls representing treatment arms.
When a new participant arrives, their factor levels identify the relevant urns — one urn per factor-level pair.
An imbalance score d is computed for each matched urn using the configured measure (
D).The urn with the highest imbalance is selected (
urn_selectionmethod).A ball is drawn from that urn. Its color determines the treatment assignment.
The urn composition is updated:
alphaballs of the assigned treatment andbetaballs of each unassigned treatment are added back.
This adaptive mechanism naturally corrects imbalances: the most imbalanced stratum drives the assignment, shifting probability toward underrepresented arms across all relevant factor levels.
Tip
For a two-arm trial with w=1, alpha=0, beta=1, the scheme
starts with equal probability and progressively favours the arm with
fewer assignments — achieving good balance without being deterministic.