# Regression discontinuity at a score cutoff

Sixth part of the city launch study. A rule gives an offer to drivers with a service score of 70 or more and to nobody
below. The read compares drivers just above and just below that line: a line on each side with triangular weights at a
plug-in bandwidth of the Imbens and Kalyanaraman kind, with a bias-corrected 90% interval. Three checks run beside it:
McCrary's density test, the same read on last quarter's trips, and ten placebo lines. The simulation draws synthetic
drivers (5,000 in the base case, 1,250 or 20,000 in four settings) 1,000 times in each of 19 settings and scores the call
on an offer, keep it or drop it, against an assumed break-even of 3 extra trips a week, at planted effects from 0 to 6
trips.

In the simulation, where I drew the baseline smooth at the line, the point call was right in 97.5% of runs on an offer
worth nothing and 98.0% on one worth twice the break-even. Those rates depend on how far I set the effects from the
break-even: 81.6% and 87.0% at half and 1.5 times it, and 85.8% and 83.4% with 1,250 drivers. The 90% interval could not
settle the call in 58.3% and 56.6% of the same runs. When 20% of drivers near the line moved across and motivation drove
who moved, an offer worth nothing read +2.51 trips on average and the call was wrong in 35.9% of runs; the density test
fired in all 1,000, as it must when I pile movers above the line. When 20% moved each way in matched flows, the read stayed
+4.25 trips high and the call was wrong in 79.8% of runs while the density test fired in 8.9%.

Added after the results, and declared before its runs: a sweep of that two-way setting put its wrong calls anywhere from
12.9% (a 5% share each way) to 100% (a 40% share), so the 79.8% is a property of my inputs. Deciding from the interval with
all three checks quiet, the rule the page recommends, settled the two-way setting wrongly in 2.8% of runs, and in 17.1%
(against 0.6% settled rightly) when motivation did not show in last quarter's trips.

The drivers, effects, break-even and every failure are my choices, and the same author wrote the generator, the reads,
the checks and the scoring, so every result is a self-test. The smooth baseline and the flat density under two-way
moving are true by construction. This shows how the design behaves, not how often drivers move in a real marketplace or
what any real offer does.

## Why it is a round of this study (overlap test)

The other parts read a change with a holdout, a synthetic control, or a series before and after. None of them, and no
other study on this site, reads a change that a rule gives by score. Same question family (what did this change do when
no A/B test exists), so a round of this study, not a new study.

## Run it

    python3 -m pip install -r requirements.txt
    python3 -m cutoff.run run base            # then each of the 19 settings named in the protocol
    python3 -m cutoff.run summarise           # runs-regression-discontinuity.csv.gz, results-regression-discontinuity.json
    python3 -m cutoff.run check               # replays every stored row from its seed
    python3 -m pip install -r requirements-crosscheck.txt
    python3 -m cutoff.crosscheck              # the published packages, on a sample of runs
    python3 -m cutoff.addendum run tw_s05     # then each of the 18 settings in protocol-regression-discontinuity-addendum.json
    python3 -m cutoff.addendum bandwidth base # then curved and two_way; needs requirements-crosscheck.txt
    python3 -m cutoff.addendum summarise      # runs-regression-discontinuity-addendum.csv.gz, ...-bandwidth.csv.gz, results-...-addendum.json
    python3 -m cutoff.addendum check          # replays the sweep's stored rows from their seeds
    python3 -m pytest tests/test_cutoff_methods.py tests/test_cutoff.py tests/test_cutoff_addendum.py tests/test_cutoff_page.py
    python3 site/render_cutoff.py             # regression-discontinuity.html

`cutoff.run run` refuses to start unless `protocol-regression-discontinuity.json` matches the hash pinned in
`cutoff/run.py` and, inside a git checkout, is committed unmodified; `cutoff.addendum` does the same for its own protocol.
Each setting writes its own file (to `cutoff-runs/` or `cutoff-runs-addendum/`, or the folder in `CUTOFF_PARTS`) and
renames it when complete, so a setting that stops partway leaves no finished file.

## Files

- `DESIGN-regression-discontinuity.md`: the design, the planning table and the 16 predictions, written before any
  result; its hash and the protocol's are in `DESIGN-regression-discontinuity.sha256`.
- `protocol-regression-discontinuity.json`: every term, setting, read, check and scoring rule.
- `cutoff/sim.py`: the generator and who moves. `cutoff/reads.py`: the local fits, the plug-in bandwidth, the density
  test, the balance check and the placebo lines. `cutoff/planning.py`: arithmetic on the generator, with no simulated
  outcome. `cutoff/run.py`: the run, the summaries, the predictions and the replay. `cutoff/crosscheck.py`: the
  comparison with rdrobust and rddensity.
- `runs-regression-discontinuity.csv.gz`: every setting and run (19,000 rows). `results-regression-discontinuity.json`:
  the summaries with their 95% ranges, the money arithmetic, the worked examples and the predictions.
  `results-regression-discontinuity-crosscheck.json`: the comparison with the packages.
- Added after the results: `DESIGN-regression-discontinuity-addendum.md` (with its hashes in
  `DESIGN-regression-discontinuity-addendum.sha256`) and `protocol-regression-discontinuity-addendum.json`, committed
  before `cutoff/addendum.py` and before its runs; `runs-regression-discontinuity-addendum.csv.gz` (the two-way sweep,
  18,000 rows), `runs-regression-discontinuity-bandwidth.csv.gz` (the two other bandwidths on three settings, 3,000 rows)
  and `results-regression-discontinuity-addendum.json` (the sweep, the recommended rule on every setting, the bandwidth
  variants and parts, and its 17 predictions).
- `site/render_cutoff.py`, `site/cutoff.css`: build the page; the render stops if a sentence's claim no longer holds.
- `tests/test_cutoff_methods.py`, `tests/test_cutoff.py`, `tests/test_cutoff_addendum.py`, `tests/test_cutoff_page.py`:
  planted checks on the methods, the replay and summaries, the addendum (which also pins every frozen file byte for byte),
  and every number on the page against the results. One page test uses a private word list that is not in this download,
  so it is skipped here, with that reason stated, and one addendum test needs rdrobust and is skipped without it.

## What the plug-in rule is, and is not

The plug-in rule follows the Imbens and Kalyanaraman bandwidth. Checked after the results against two working-paper
versions of the paper, the `rdd` R package and the older version of this rule kept inside the rdrobust R package: the
constants 1.84, 3.56 and 3.4375 match all four. The term that regularizes the curvature is 2160 in `cutoff/reads.py` and
in that rdrobust version, and 720 in the working papers and `rdd`; the journal version could not be read. The
code keeps 2160. Rerun with 720, or with the bandwidth rdrobust's current rule picks, the headline wrong-call rates moved
by under 3 points (2.5% to 1.9% and 4.5% on the clean line, 79.8% to 77.1% and 82.0% with 20% moving each way).

It is not the bandwidth rdrobust chooses: over 50 runs each of two settings its bandwidth was a median 1.14 and 1.06
times the package's, ranging from 0.69 to 4.07 times. It hardly narrows with more drivers because this baseline has no
curvature gap at the line, so the curvature it reads is noise that shrinks as drivers grow. The fits themselves, at the
same bandwidth, match rdrobust. For a real decision use the packages.
