# TED QSP Model

Quantitative systems pharmacology model of Thyroid Eye Disease (Graves'
orbitopathy), implemented as an R Shiny app. Full equations, parameters, and
literature sources are in `docs/model-spec.md` — read that before touching
`R/`. For the full development story — where every piece of data came from,
how it was collected, the design decisions and bugs found while building the
code, and a complete bibliography — see `docs/DEVELOPMENT.md`.

## Running

```
Rscript scripts/install_packages.R   # one-time: deSolve, shiny, bslib, ggplot2, testthat
cd app
Rscript -e "shiny::runApp('.')"
```

## Testing

```
Rscript -e "testthat::test_dir('tests/testthat', reporter = 'summary')"
```

## Layout

- `R/` — model code: PK (`pk_models.R`), receptor occupancy/IGF-1 biomarker
  (`target_engagement.R`), natural-history disease drive
  (`natural_history.R`), fibroblast/cytokine mechanism core
  (`mechanism_core.R`), CAS/proptosis/diplopia mapping
  (`clinical_translation.R`), per-drug parameter registry
  (`drug_registry.R`), and the top-level `ted_simulate()` assembly
  (`simulate.R`). `load_all.R` sources everything in dependency order.
- `app/app.R` — Shiny UI/server.
- `docs/model-spec.md` — every equation, parameter, and its source or
  confidence tag (`[LIT]` / `[CALIB]` / `[ASSUMED]`), plus an honest
  calibration-status section.
- `data/digitized/` — (empty so far) target location for digitized trial
  figures used to calibrate the mechanism core.
- `tests/testthat/` — PK/mechanism sanity checks.

## Status

Architecture is in place and swappable per-drug (teprotumumab is the only
fully literature-grounded drug so far; others are stubs — see
`R/drug_registry.R` `confidence` field). Mechanism core structure is
implemented but not yet curve-fit to real trial data. See
`docs/model-spec.md` Section 8 for the full calibration TODO list.
