# A regression discontinuity at a score cutoff (design, declared before any result)

Sixth part of the city launch study. Question: when a rule gives an offer only to drivers at or above a score, how often
does comparing drivers just above the line with drivers just below it make the right call on the offer, how much does the
choice of bandwidth matter, and when it fails because drivers move themselves across the line, do the usual checks see it?

This file, the frozen protocol `protocol-regression-discontinuity.json` and the code that draws the drivers, makes the
reads and scores the calls (`cutoff/sim.py`, `cutoff/reads.py`, `cutoff/planning.py`, `cutoff/run.py`) are committed before
any reported run. `cutoff/run.py` pins the protocol's SHA-256 and refuses to run if the protocol differs from the pin or,
inside a git checkout, is not committed unmodified.

What ran before this commit, none of it printing a read, a call, a rate, a bandwidth or a z from a simulated run:

- The tests on known answers (`tests/test_cutoff_methods.py`). They build their own data, except that they draw a few runs of
  the frozen seed (runs 0, 3 and 4) to test that movers land where stated, that settings are paired and that a constant
  effect shifts every read by exactly itself. They assert on those properties and print no value.
- A smoke run on a different seed (entropy 999), three runs per setting, printing only whether the outputs are finite, how
  many fake lines ran and the time a run takes.
- A comparison with the published packages on that different seed, one run of the base setting: the fits at one bandwidth
  (they match within rounding), the package's bandwidth divided by the plug-in's, and the names of the package's output fields.
- The planning tables below, which are numerical integration over the generator and read no simulated outcome. They
  also set the curve in the `curved` setting and the step in `lumpy`, so that those settings can bite. That is a choice of
  fault strength made with the arithmetic in view, stated here as such.

## Overlap test: what the published pages answer, and what this part adds

- Parts one to three compare a launch city, enrolled members or switching merchants with units chosen to look like them, and
  each has a selection problem to adjust for. Nobody on those pages is assigned by a known rule.
- Part four sizes a randomized holdout. Part five reads a public series with no planted truth.
- This part uses a design those pages do not: assignment by a known score and line, read at the line. None of those pages
  covers a bandwidth, a density test, placebo cutoffs or people moving across a line, and a search of the study cards and
  study pages found no other published study that does. Same question family (measuring a change with no randomized
  holdout), so a part of this study, not a new study. Kept to one short page: what the design needs and how it breaks.

## 1. The terms (declared assumptions, not results)

- The offer costs US$6 a driver a week; each extra completed trip adds US$2 of contribution. So the offer pays above **3
  extra trips a week** per driver (the break-even). It runs for 12 weeks.
- Planted effects, all chosen here: 0, 1.5, 3, 4.5 and 6 trips a week, that is 0 to 2 times the break-even. At exactly 3
  either call costs nothing, and extending is counted right, so that cell is a coin flip by construction.

## 2. The simulated drivers (all the author's choices)

- 5,000 drivers in the base case. Service score: Normal(66, 10), clipped to 0 to 100. The line is 70: at or above it the
  offer applies, below it does not, with no exceptions (a sharp rule).
- Weekly trips without the offer: 60 + 0.5 x + A tanh(x / L) + 8 M + 16 e, where x is the score the driver would have had
  unmoved, minus 70; M is the driver's motivation, Normal(0, 1), unrelated to the score; e is noise, Normal(0, 1). Base case A =
  2 and L = 10, a gentle curve.
- Last quarter's trips, which the offer cannot affect: the same curve + 8 M + 16 e', with its own noise e'.
- **The baseline is smooth at the line because I drew it that way.** The design needs that assumption, and in this simulation
  it holds by construction wherever nobody moves (FM5), so the base case's recovery is a check of the arithmetic and of power, not
  evidence the design works in the world.

## 3. Settings

Each setting runs 1,000 times (seed entropy 8053; run r of a setting draws from SeedSequence([8053, group, r]), group 1, 2
and 3 for 5,000, 1,250 and 20,000 drivers). Settings of one size reuse the same draws, so they are paired and are not
independent of each other.

| Setting | What changes |
|---|---|
| base | nothing moves; the gentle curve |
| curved | A = 10, L = 8, a steep S around the line, smooth at the line; nobody moves |
| lumpy | a second change steps trips up by 3 at scores 60, 65, 70, 75 and 80, in the outcome only |
| move_02, 05, 10, 20, 40 | drivers within 3 points below the line move across, landing within 1 point above it. A driver in that band moves with chance share x 2 Phi(M), so the average chance is the share and movers are the more motivated (mean M = 1 / sqrt(pi), about +0.56). A move changes the score, never the driver's trips |
| move_unrelated | share 20%, chance of moving unrelated to motivation |
| two_way | share 20% each way: the more motivated below the line move up, and with chance share x 2 Phi(-M) the less motivated within 3 points above it let their score slip to within 1 point below it. The score's density stays nearly flat |
| two_way_hidden | the same, but motivation does not show in last quarter's trips |
| local | the effect is 6 trips at the line and grows by 0.4 a point above it. Below the line, what the offer would do if extended is max(0, 6 + 0.4 x) |
| few, many | the base case with 1,250 and 20,000 drivers |
| noisy | the base case with noise of 24 trips instead of 16 |
| move_10_few, move_10_many | share 10%, with 1,250 and 20,000 drivers |
| move_20_strong, move_20_weak | share 20%, motivation worth 12 and 4 trips instead of 8 |

## 4. The reads

Each read estimates the jump in weekly trips at the line.

- **Primary read:** a straight line on each side, triangular weights, at a plug-in bandwidth of the Imbens and Kalyanaraman
  kind computed from the run's own data. Its 90% interval is the bias-corrected one of Calonico, Cattaneo and Titiunik: a curve
  (order 2) on each side at the same bandwidth, with that fit's own standard error.
- The same line at fixed half-widths of 2, 5, 10 and 20 points, each with its conventional 90% interval.
- One line on each side over all drivers with equal weights, and the raw gap (everyone above minus everyone below).
- Two donuts: drop drivers within 1 point and within 3 points of the line, then the same rule and line.

All standard errors let the noise differ by driver (the hc1 variance).

## 5. The checks

- **Density:** McCrary's test at the line; fires at |z| > 1.96.
- **Balance:** the bias-corrected read on last quarter's trips, at its own plug-in bandwidth; fires at |z| > 1.96.
- **Placebo lines:** the bias-corrected read at ten fake lines (57.5 to 67.5 and 72.5 to 82.5, every 2.5 points), at the read's
  bandwidth, each fake line seeing only drivers on its own side of the real line; fires when any |z| exceeds 2.807, the bar
  for ten lines at 5%.

Fake lines at 60, 65, 75 and 80 sit exactly on the `lumpy` steps, because I placed both. A catch there is a self-test (FM4).

## 6. The calls and the scoring

The planted effect is constant in every setting but `local`, and every read and check is unchanged by adding a constant jump
apart from the read shifting by exactly that jump (a test proves it on real draws). So each run is stored once, and the calls
at each planted effect use the same runs. They are not independent across planted effects.

- **Point call:** extend the offer when the read is above 3 trips. Right when the planted effect is at least 3.
- **Interval call:** pays when the whole 90% interval is above 3, does not pay when it is all below 3, cannot tell otherwise.
- **With checks:** if any check fires, hold and make no call.
- Reported per setting: average error, spread, interval coverage, the share of each call, the share of each check firing,
  with Wilson 95% ranges over the runs. No figure pools settings.
- A run that raises an error is recorded, counted and left out of its cell. Nothing is re-run unless a re-run is declared
  first. Every setting runs once.
- Worked examples, chosen by this rule: run 0 of base at a planted 6 trips, and run 0 of move_20 at a planted 0.
- Money, from the terms: the offer's cost for the 34.5% of base-case drivers at or above the line (the share the score's
  distribution gives), a week and over the 12 weeks.

Cross-check, run after the runs and reported whatever it shows (`cutoff/crosscheck.py`, needing `requirements-crosscheck.txt`):
on runs 0 to 49 of base and move_20, the line and the curve at the same bandwidth against rdrobust; the plug-in bandwidth
against that package's own rule, which is a different rule; on runs 0 to 99 of base, move_05, move_20 and two_way,
McCrary's calls against the rddensity package's test, which is a different test.

## 7. Planning table (arithmetic on the generator, no simulated outcome)

What a fixed half-width reads with no planted effect, in the limit of many drivers, and its standard error at 5,000 drivers.

| Half-width (points) | Standard error, line | Standard error, curve | base | curved | move_20 | two_way |
|---:|---:|---:|---:|---:|---:|---:|
| 2 | 2.89 | 4.23 | +0.00 | +0.01 | +2.68 | +4.51 |
| 5 | 1.84 | 2.69 | +0.02 | +0.14 | +2.64 | +4.37 |
| 10 | 1.33 | 1.93 | +0.09 | +0.82 | +2.15 | +3.69 |
| 20 | 1.02 | 1.44 | +0.36 | +2.75 | +1.74 | +2.91 |

A test compares the stored runs' average reads with this table, a second route to the same numbers.

## 8. Predictions

Scored mechanically by `cutoff/run.py`. The first several restate what the construction and the table imply; they guard the
code more than they test the design.

1. Base: the primary read's average error is within 0.5 trips.
2. Base: the bias-corrected 90% interval holds the truth in 87% to 93% of runs, and the conventional one no more often.
3. Base: the point call is right in at least 97% of runs at planted 0 and 6, and in 85% to 97% at planted 1.5 and 4.5.
4. Base: at planted 3, the break-even, the point call extends in 40% to 60% of runs.
5. Base: the interval call cannot tell in at least 30% of runs at planted 0 and at planted 6.
6. Curved: the 20-point read's average error is above +2 trips, the 5-point read's within 0.5, the primary read's within 1.
7. One-way moving: the primary read's average error is above +1.5 trips at a 20% share and above +3 at 40%.
8. Density: fires in at least 90% of runs at a 20% share, in at most 15% of base runs, and in at most 25% at a 2% share.
9. Two-way moving: the primary read's average error is above +3 trips while density fires in at most 30% of runs.
10. Balance: fires in at least 60% of two-way runs, and in at most 10% when motivation does not show in last quarter's trips.
11. Placebo lines: fire in at most 10% of base runs, in more of the lumpy runs than the base runs but in fewer than half, and
    lumpy's primary read is at least +1.5 trips off.
12. Placebo lines: fire in at most 25% of runs at a 20% one-way share.
13. Moving unrelated to motivation: density fires in at least 90% of runs although the primary read stays within 1 trip.
14. Donuts at a 20% one-way share: the 3-point donut's average error is within 1 trip, the 1-point donut's above +0.75.
15. 1,250 drivers: the point call is right in under 97% of runs at planted 0 and at planted 6.
16. Local effect: the read lands within 0.5 trips of the 6 at the line, while the effect averaged over drivers below the
    line is under the break-even.

## 9. Limits declared now

- Self-test (FM4): I wrote the generator, the reads, the checks and every failure. Each check catches what I built it to
  catch, and each misses what I built it to miss. How often these faults happen in a real marketplace, this cannot say.
- Assumptions (FM10): every right-call rate follows from the planted effects, the 3-trip break-even, the number of drivers,
  the noise, how much motivation is worth and how far drivers can move. The sweeps move several of these; the band and the
  landing zone stay fixed at 3 points and 1 point.
- By construction (FM5): the baseline is smooth at the line wherever nobody moves, and the density is flat under two-way moving
  because I made the flows match.
- A sharp rule: everyone above takes the offer and nobody below does. Fuzzy take-up, a coarse score with few distinct
  values, spillovers between drivers near the line and effects that fade are left out.
- A read at the line says what the offer does for drivers near the line. For anyone else it needs an assumption the design
  cannot test.
- This shows a method in a simulation, not evidence about any real score, offer or marketplace, and not job experience.
