Metadata-Version: 2.4
Name: mstrial
Version: 0.1.0
Summary: Multiple sclerosis trial design and endpoints: ARR, time to confirmed worsening, NEDA, negative binomial sample size for lesion counts, MRI schedules under a budget, PIRA power through the whole pipeline, and the endpoint landscape of registered trials.
Author: Cedric Conday
License: MIT
Project-URL: Homepage, https://github.com/CedricConday/mstrial
Keywords: multiple sclerosis
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Requires-Dist: pandas>=2
Requires-Dist: requests>=2.28
Requires-Dist: msclinical>=0.1.0
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Dynamic: license-file

# mstrial

Trial design and endpoints for MS, on top of [msclinical](https://github.com/CedricConday/msclinical): endpoints from plain tables, sample size for lesion counts, MRI schedules, power for PIRA endpoints through the whole pipeline, and what registered trials actually measure.

```bash
pip install mstrial
mstrial <tool> --help
```

| Tool | Command | What it does |
|---|---|---|
| [`endpoints`](#endpoints) | `mstrial endpoints` | ARR, time to confirmed worsening, NEDA-3 and new-lesion rate in one call |
| [`lesionpower`](#lesionpower) | `mstrial lesionpower` | negative binomial sample size for lesion-count endpoints |
| [`scanplan`](#scanplan) | `mstrial scanplan` | MRI schedule under a scan budget, with transient enhancement modelled |
| [`pirapower`](#pirapower) | `mstrial pirapower` | power for PIRA endpoints through rating noise, confirmation and attribution |
| [`registry`](#registry) | `mstrial registry` | endpoint landscape of registered MS trials, live from ClinicalTrials.gov |

Research software, not a medical device. MIT licence. Each section below keeps the tool's own results and the
corrections that three independent reviews made to them.

## endpoints

*formerly msendpoints*

The standard MS trial endpoints from four plain tables, in one call: **annualised relapse rate** with
a negative binomial rate ratio and 95 % CI, **time to confirmed disability worsening** (EDSS-plus or
EDSS, via [edssplus](https://github.com/CedricConday/msclinical#edssplus)) with Kaplan-Meier and log-rank,
**NEDA-3** over year one (via [neda](https://github.com/CedricConday/msclinical#neda), assessable
patients only) and **new T2 lesions** per patient-year.

```bash
pip install mstrial
mstrial endpoints patients.tsv visits.tsv relapses.tsv --mri mri.tsv --horizon 2
```

`patients.tsv`: patient, arm, start, end. The output is one JSON a statistician can check line by line.
An arm with no events gets rates and a stated reason, never a rate ratio of zero with a made-up interval.

## lesionpower


Sample size and power for multiple sclerosis trials whose endpoint is a **count of new lesions**.
Counts per patient are overdispersed, so a Poisson calculation promises too few patients. lesionpower
fits a negative binomial to pilot counts and gives the closed-form sample size (Keene et al. 2007;
Zhu and Lakkis 2014), with a simulation check for small counts.

```bash
pip install mstrial
mstrial lesionpower fit pilot.tsv --column new --exposure years      # mean, dispersion, n per arm for 30/50/70 %
mstrial lesionpower n --mu 4.2 --k 1.3 --reduction 0.5 --simulate
```

### What the pilot data does to the answer

On the 24 longitudinal MSLesSeg patients (expert masks, new lesions from
[mscard](https://github.com/CedricConday/mscard), per patient-year of follow-up): mean 4.2 new
lesions per year, dispersion k = 1.33, and not one patient with zero. A 50 % reduction then needs 37
patients per arm for 80 % power at one year.

The same data carries a warning. [gtdrift](https://github.com/CedricConday/msdataqc#gtdrift) finds that about
half the lesion sites in MSLesSeg's multi-visit ground truth appear and disappear in ways a chronic
lesion does not, so part of the "new lesion" count is annotation, not disease. A mean inflated by
annotation noise makes the sample size look smaller than it is. Fit on counts from the reading
protocol the trial will use.

## scanplan


Monthly scans or more patients? For a gadolinium-enhancing lesion endpoint the answer is not obvious:
enhancement lasts about three weeks, so a sparse schedule misses most enhancing lesions, while a dense one
spends the scan budget on few patients. scanplan models that trade-off (negative binomial lesion counts,
exponential enhancement duration, Keene et al. 2007 power) and returns the schedule with the highest power
for a fixed number of scans. For new T2 lesions, which persist, fewer scans and more patients always win.

```bash
pip install mstrial
mstrial scanplan --budget 600 --years 1 --lam 4.2 --k 1.33 --reduction 0.3            # enhancing lesions
mstrial scanplan --budget 600 --years 1 --lam 4.2 --k 1.33 --reduction 0.3 --endpoint t2
```

With 600 scans, 4.2 new lesions per patient-year and dispersion 1.33 (the MSLesSeg pilot fit from
[lesionpower](https://github.com/CedricConday/mstrial#lesionpower)), for a 30 % reduction on enhancing lesions:

```
interval_days  scans_per_patient  years_covered  patients_per_arm  detect_p  control_mean_count  power
            30                 13          0.986                23     0.532               2.203  0.184
            60                  7          0.986                42     0.330               1.366  0.247
            91                  5          0.997                60     0.228               0.953  0.278
           182                  3          0.997               100     0.115               0.483  0.286
           365                  2          0.999               150     0.058               0.241  0.250
best: every 182 days, 100 per arm, power 0.29
```

Under this much between-patient overdispersion the 2/k term dominates the variance, so even for a
transient endpoint more patients scanned twice beat fewer patients scanned monthly. With counts close to
Poisson (`--k 20`) the optimum moves to quarterly scans with fewer patients.

The model and its assumptions (one enhancement duration for all lesions, no seasonal or treatment effect
on duration) are in `mstrial/scanplan/core.py`. Research software. MIT.

## pirapower


PIRA (progression independent of relapse activity) is becoming a trial endpoint. Its power is usually
computed as if the true PIRA events were observed. They are not. Every event passes through EDSS rating
noise, a confirmation window and relapse attribution before it is counted. pirapower simulates that whole
pipeline: [sim](https://github.com/CedricConday/msclinical#sim) cohorts with a known PIRA reduction,
[edssplus](https://github.com/CedricConday/msclinical#edssplus) for confirmed worsening,
[pirma](https://github.com/CedricConday/msclinical#pirma) for attribution, and a log-rank test on time to first PIRA.

```bash
pip install mstrial
mstrial pirapower --n 250 500 1000 --effect 0.3 --years 2 --noise 0.15 --confirm-days 168 --reps 100
```

### A 30 % true reduction, two years (`results/pirapower/results/power.tsv`, 60 simulated trials per cell; regenerated 2026-09-30)

| EDSS misrating | Confirmation | 250 per arm | 500 per arm | 1000 per arm |
|---|---|---:|---:|---:|
| 15 % of visits | 24 weeks | 0.15 | 0.30 | 0.57 |
| 30 % of visits | 24 weeks | 0.22 | 0.22 | 0.62 |
| 30 % of visits | 12 weeks | 0.25 | 0.37 | 0.67 |

Even 1000 patients per arm reach only about 60 % of the conventional 80 % power. The ratio of first-PIRA event
counts between arms is 0.72 to 0.76, against a true PIRA rate ratio of 0.70: events that are really rating noise
or misattributed steps dilute the effect. Shorter confirmation adds noise events but adds real events faster, and
gains power here. With 60 replicates per cell each power has a standard error of about 0.06, so neighbouring
cells within about 0.1 of each other are not distinguishable.

The simulation model is simple and its parameters are in sim: PIRA 0.12 episodes per patient-year, EDSS
every 3 months, and in the active arm a relapse and new-lesion rate ratio of 0.5 besides the PIRA effect (the
default two-arm design). These numbers were regenerated after an independent review found that sim's
noise levels had simulated different cohorts; the earlier table is superseded. Research software. MIT.

## registry

*formerly mstrials*

Which endpoints do multiple sclerosis trials actually measure? registry asks ClinicalTrials.gov through its
public API. It searches every registered MS study whose outcome measures mention an endpoint (PIRA, slowly
expanding lesions, paramagnetic rim lesions, central vein sign, neurofilament light, GFAP, NEDA, EDSS-plus,
SDMT, OCT, brain atrophy) and counts them by phase, status and start year. Every matched study is written
out with its NCT number, so each count can be checked.

```bash
pip install mstrial
mstrial registry --out studies.tsv
```

### Landscape on 2026-09-30 (`results/registry/results/`)

```
studies  interventional  phase 3  recruiting or not yet  started 2023 or later
endpoint                                                                                                
SDMT / cognition              441             342       62                    104                    150
brain atrophy                 236             201       77                     34                     39
neurofilament light           167             121       33                     60                     86
OCT retina                     85              53        4                     25                     20
NEDA                           63              35       16                     14                     23
GFAP                           47              26        4                     26                     27
paramagnetic rim lesions       25              19        3                     14                     15
PIRA                           23              12        8                     12                     16
EDSS-plus / composite          10               8        1                      2                      4
central vein sign              10               4        0                      4                      4
slowly expanding lesions        9               7        2                      5                      5
```

PIRA, the endpoint the progressive-MS field is converging on, appears in the outcomes of 23 registered MS
studies, 8 of them phase 3. Slowly expanding lesions appear in 9, paramagnetic rim lesions in 25 and the central
vein sign in 10. The tools that measure those endpoints ([pirma](https://github.com/CedricConday/msclinical#pirma),
[lesiontrack](https://github.com/CedricConday/lesiontrack), [mscard](https://github.com/CedricConday/mscard))
matter for a few dozen trials now, and for many more soon.

Precision was checked by reading the outcome text of every hit for three endpoints. All 9 slowly expanding
lesion hits and all 10 central vein sign hits contain the phrase; 22 of 25 paramagnetic rim lesion hits do (the
other three mention rim lesions another way or not at all). The search terms are short quoted phrases ("slowly
expanding", not "slowly expanding lesion", which the API matches exactly and which misses every "lesions";
unquoted terms match the words anywhere, so "slow-wave" plus "Expanded Disability" counted as a hit in an
earlier version). The other counts are outcome-text matches, not a curated review. Research software. MIT.
