# Moorfields teaching data

These notes cover the Moorfields table and export examples. Part 4 uses a
different dataset; see the [Ghana sepsis teaching data notes](ghana_sepsis_README.md)
for its sample data, heatmap values, preparation details, and source credits.

These files support new teaching tables and figures based on public clinical
data. They are **not an exact numerical reproduction** of the published paper.
The lesson uses an explicit baseline and annual-visit selection rule, reports
the resulting sample sizes, and does not fit the paper's regression models.

## Source and credit

Fasler K, Moraes G, Wagner SK, et al. (2019). *One- and two-year visual outcomes
from the Moorfields age-related macular degeneration database: a retrospective
cohort study and an open science resource.* BMJ Open 9:e027441.
[Paper](https://doi.org/10.1136/bmjopen-2018-027441).

Fasler K, Moraes G, Wagner SK, et al. (2020). *Data from: One and two year visual
outcomes from the Moorfields age-related macular degeneration database: a
retrospective cohort study and an open science resource.* Dryad.
[Dataset](https://doi.org/10.5061/dryad.97r9289).

The raw CSV and source data dictionary were obtained from the public
[eyedata repository mirror](https://github.com/tjebo/eyedata/tree/main/data-raw/fasler)
on 1 November 2026. The article is CC BY-NC 4.0. Dryad datasets are released
under CC0; see [Dryad's dataset reuse terms](https://datadryad.org/terms).
The new preparation and teaching code was written for this seminar.

## Files

- `moorfields_raw.csv`: unchanged semicolon-delimited source
  `Moorfields_AMD_Database_1.csv` (40,764 visit rows, 3,357 patients). The
  source already contains one selected eye per patient.
- `moorfields_source_dictionary.rtf`: unchanged source README explaining the
  original column names and coding.
- `moorfields_baseline.csv`: comma-delimited teaching cohort, one row for each
  of 3,355 patients with a valid day-zero visual-acuity measurement.
- `moorfields_followup.csv`: comma-delimited teaching observations at baseline,
  year 1, and year 2 (8,623 rows). A patient can contribute up to three rows.
- `lab_cohort.csv`: the previous fictional teaching dataset, retained separately.

SHA-256 of the unchanged raw CSV:
`c92ff879e74c0743c03c1e95e0e02086450dee67b22eceb72a5c65cfb558ad50`.

## Preparation rules

Rebuild both teaching CSVs from the project root with:

```sh
Rscript scripts/prepare_moorfields.R
```

Download the [preparation script](../../../scripts/prepare_moorfields.R).

The script uses base R and the checked-in raw CSV; it does not fetch data or
install packages. Optional arguments are an input CSV and output directory.

1. Read the source using `sep = ";"`; retain the original anonymised patient
   identifier. Check that each patient has one selected eye.
2. Define a valid visual-acuity score as non-missing and between -50 and 100
   ETDRS letters, inclusive. The lower limit allows the paper's coding of very
   low acuity. This particular source has no negative scores and no scores
   outside that range; it has two missing visual-acuity rows.
3. Require an actual `FollowupDays == 0` visit with valid acuity for the teaching
   baseline cohort. The source dictionary calls day zero the first appointment.
   Two patients have no day-zero visit and are excluded; their later visits are
   not substituted as baseline. No day-zero rows have missing or out-of-range
   visual acuity.
4. Restrict all annual selections to this baseline cohort. For year 1 choose the
   valid visit nearest day 364 within days 308–420. For year 2 choose the valid
   visit nearest day 728 within days 672–784. These are the paper's 52/104-week
   targets with eight-week windows, applied to the released data.
5. Break equal-distance ties by the earlier visit day, then by original source
   row. Select no more than one observation per patient per timepoint. Do not
   impute absent follow-up observations or carry observations forward.
6. Classify acuity as `Poor` at ≤35 letters, `Intermediate` at >35 and <70
   letters, and `Good` at ≥70 letters. These are descriptive categories, not
   treatment groups.

The script asserts the required columns, one baseline row per patient, unique
patient/timepoint combinations, valid scores, and annual visit windows.

## Counts and denominators

| Timepoint | Patients with a selected valid observation | Without an observation in that window |
|---|---:|---:|
| Baseline | 3,355 | 0 within the teaching cohort |
| Year 1 | 3,355 | 0 |
| Year 2 | 1,913 | 1,442 |

The baseline vision categories contain 451 patients with poor vision, 2,071
with intermediate vision, and 833 with good vision. Recorded baseline age and
recorded sex are complete in this teaching cohort.

Percentages at each timepoint use the patients observed at that timepoint.
Year 2 therefore describes a smaller group, and a change between the stacked
bars does not by itself measure within-person improvement or a treatment effect.

## Teaching column dictionary

`moorfields_baseline.csv`:

| Column | Meaning |
|---|---|
| `patient_id` | Original anonymised identifier; one eye per patient |
| `age` | **Recorded baseline age in years, after source de-identification** |
| `sex` | Recorded source sex: `Male` for source `Gender == 0`, `Female` for `Gender == 1` |
| `baseline_va` | Day-zero visual acuity in ETDRS letters; higher scores indicate better acuity |
| `baseline_vision` | `Poor`, `Intermediate`, or `Good`, derived from `baseline_va` |

`moorfields_followup.csv`:

| Column | Meaning |
|---|---|
| `patient_id` | Identifier linking to the baseline teaching cohort |
| `timepoint` | `Baseline`, `Year 1`, or `Year 2` |
| `followup_days` | Actual selected visit day relative to the first appointment |
| `va` | Selected visit's visual acuity in ETDRS letters |
| `vision` | `Poor`, `Intermediate`, or `Good`, derived from `va` |

**Age needs special care.** The source dictionary states that ages ≤65 were
recoded to 60 and ages >90 to 99. Keep those recorded values rather than trying
to reconstruct patients' ages. Label tables and axes “Recorded baseline age,”
and describe any age summaries as summaries of those recorded values. Peaks at
60 and 99 in a histogram partly reflect this de-identification rule.

The public file and these simple selection rules do not reproduce every number
in the article. Comparisons with the paper are for discussing design and
presentation; captions should identify these outputs as teaching analyses of
the released data. No claim of author endorsement is intended.
