# Identity resolution when signals disappear: design

Written and committed before any result was read: no stitching rule had run on any generated data when this file was
committed. A change after this commit goes in a section at the end headed `## Amendment N: <what changed>`, and the
page reports it.

## 0. Question

As identifying signals disappear (cookies capped or split by a browser family, device advertising ids withheld,
consent declined or withdrawn, a platform migration that re-keys every id), how wrong do user counts, conversion rates
and channel attribution get under each stitching rule, and which rule stays honest about what it cannot know?

## 1. Data: synthetic, on fixed seeds

Every person, device, visit and order is generated by `idr/generate.py`; no real person or company data is used. The
generator keeps the true person behind every row, so every measure is scored against the truth. No public record
linkage benchmark is used: the error rates below are declared assumptions, and the page labels them so. Seeds 0 to 9;
each seed draws a new population, and the six scenarios are applied to the same population (so scenarios are compared
on the same people).

All of the following are assumptions, chosen to look like a mid-sized online shop with a content site, an app and a
login.

### People and households

- 4,000 households of 1, 2 or 3 people (probability 0.40, 0.35, 0.25).
- 55% of people hold an account (a login). In households of 2 or more, with probability 0.08 the first two members
  share one account.
- 55% of people work at one of 300 offices; an office has one network address.

### Devices and browsers

- Every person has a phone; 50% of phones have the shop's app. 70% of people have a laptop. 35% of households have a
  tablet, shared by every member when the household has 2 or more people.
- Each browser belongs to family A (a privacy-first family) or family B: phones 55% A, laptops 15% A, tablets 60% A.
- A browser's user-agent class is its device class, family and one of 4 version buckets; members of a household share
  the phone version bucket with probability 0.6.
- Each phone has a device advertising id, used by the app only.

### Visits

- Each person's visit rate is log-normal with median 0.6 visits a week and log-scale spread 0.8, capped at 8 a week,
  over a 90-day period. 40% of people arrive at a uniform day in the period; the rest are active from day 0. The
  number of visits is Poisson on the active weeks; a person with no visit is not in the data and not in the truth.
- Each visit uses the phone (weight 0.5; the app with probability 0.8 when the phone has it), the laptop (0.35) or
  the tablet (0.15), renormalised over the devices the person has.
- Network address: phone at home with probability 0.5, else a one-off mobile address; laptop at the office with
  probability 0.4 on a weekday for workers, else at home with 0.85, else one-off; tablet at home with 0.95, else
  one-off. A household's home address changes once in the period with probability 0.15.
- Channel of the first visit: paid search 0.25, paid social 0.20, display 0.08, affiliate 0.07, organic 0.25,
  direct 0.15. Later visits: direct 0.30, organic 0.18, email 0.15, paid search 0.12, paid social 0.12, display 0.07,
  affiliate 0.06.
- 20% of visits start on the content site; 55% of those continue to the shop in the same visit.
- A visit that reaches the shop buys with probability 0.03, times 1.6 for email, 1.4 for direct, 1.3 for paid search,
  times (1 + 0.15 x the person's earlier visits, at most 5).
- Account holders are logged in on 95% of app visits, 25% of web visits and 90% of purchases; a purchase without a
  login is a guest checkout with a verified email. An email visit carries a verified email in its link with
  probability 0.7.

## 2. What the data records (the baseline)

- A browser keeps one first-party cookie id, shared by the content site and the shop through link decoration; it is
  cleared with probability 0.02 per visit (then a new id).
- The app keeps an install id; a reinstall (probability 0.005 per visit) gives a new one. App rows carry the device
  advertising id. A paid channel on an app visit (paid search, paid social, display, affiliate) is recorded only
  through the device advertising id; without it the visit is recorded as direct.
- Rows carry the login id and the verified email (hashed) where present, the network address, the day and the
  user-agent class.
- A row is one visit on one key. A content-to-shop visit is one row when one key covers both sites.

## 3. Signal-loss scenarios (declared)

| Scenario | What changes |
|---|---|
| Baseline | Section 2 as written |
| Cookie loss | Family A browsers: the cookie id is re-issued when more than 7 days pass between visits to that site, and the content site and the shop keep separate ids (no link decoration); the shop row of a content-to-shop visit is recorded with channel "own content" |
| Device ids | 60% of phones withhold the device advertising id: their app rows carry none, so reinstalls are not joined and paid channels on their app visits are recorded as direct |
| Consent | 8% of people decline at their first visit; 6% of the others withdraw at a uniform time between their first and last visit. After declining or withdrawing, each visit is recorded on a one-visit key with no login, email, device id, address or user-agent class; its channel and any purchase are still recorded. A withdrawal is logged on the person's last identified row |
| Migration | From day 60 every cookie id and install id is re-issued; login ids carry over through a mapping table for 90% of accounts (the rest get new ids); verified emails are hashed with a new salt, so a pre-migration hash never equals a post-migration hash |
| Realistic | All four at once |

## 4. Stitching rules (the arms)

Consent is enforced in every rule: a one-visit key after a decline or withdrawal carries no identifier and is never a
match candidate, so no rule stitches across a withdrawal. This holds by construction; the check that counts violations
is bookkeeping, and its positive control is a planted identifier on such a row.

1. **Deterministic.** Keys that share a login id, a verified email or a device advertising id are one user (connected
   components). A first sketch said login or email only; the device advertising id is added because every app
   attribution join uses it, so leaving it out would make the deterministic rule fail on app reinstalls for a reason
   no team accepts.
2. **Deterministic plus probabilistic, point count.** Start from the deterministic users. Candidate pairs are
   identified keys that share a network address over the period (addresses seen on more than 120 keys are skipped).
   Features: shared addresses (1, 2 or more); shared address-days (0, 1, 2 or more); same user-agent class (yes,
   no); timing (one key's last visit within 3 days before the other's first, the spans overlap, or apart). Weights are
   Fellegi-Sunter match and non-match probabilities (add-one smoothing) learnt from the deterministic rule's own
   labels, never from the truth: pairs inside one deterministic user are matches, pairs between two users that hold
   different login ids of the same era are non-matches; the prior is the labelled match share. A pair links when its
   posterior is at least 0.9. Two users each holding a login id of the same era (before or after the migration) are
   never linked; pairs are checked one at a time, so a chain through a third key can still join them.
   The rule never matches a withheld device by address and timing to recover an ad click: that is the tracking the
   person opted out of.
3. **Probabilistic band.** The same model and candidates. It draws 60 linkings, each scored pair linked independently
   with its posterior probability, and reports the 5th to 95th percentile of each measure instead of one number.
   One-visit keys are not counted as users: they are reported as visits, and the users behind them are estimated as
   (one-visit visits minus the visits expected from logged withdrawals) divided by visits per identified user, where
   a withdrawer's expected visits are their identified visit rate times the days left. The estimate is added to the
   identified count in each draw.

Threshold trade-off: rule 2 is also run at posteriors 0.5, 0.7, 0.97 and 0.99, in every scenario.

## 5. Measures, against truth

- **User count error:** counted users minus true users, as a share of true users. Rules 1 and 2 count every key
  cluster, one-visit keys included (a distinct-id count).
- **Merge and split errors**, per 100 true users: a merge is each extra true person inside one counted user; a split
  is each extra counted user one true person is spread over (rows are the unit, so a shared tablet's key counts for
  every person who used it). Count error equals splits minus merges by construction; it is bookkeeping, shown so a
  near-zero count error is not read as no error.
- **Conversion rate error:** share of users with at least one purchase, counted minus true, in points.
- **Channel attribution:** each purchase credited by last touch (the last non-direct visit in the 30 days up to and
  including the purchase visit, else direct) and by position (40% first, 40% last, 20% spread over the middle visits
  in those 30 days; 50/50 with two visits, all to the one with one). The channel share error is the counted share
  minus the true share, in points, per channel. The truth applies the same rule to the true person's visits with their
  true channels, so the error measures what identity and recording loss do to the report, not whether last touch is
  a good rule.
- **Recording loss apart from stitching:** in the device id and consent scenarios part of the error is a channel the
  data never recorded; the page reports what a perfect stitch on the recorded rows would show, so that part is not
  blamed on a rule.
- **Rule 2:** the true precision of the probabilistic links it accepted against the model's own estimate (the mean
  posterior of the accepted links).
- **Rule 3:** whether each band holds the truth (coverage, per seed) and its width.

## 6. Reporting

Per scenario and rule, never pooled across scenarios: the mean over the 10 seeds and the lowest and highest seed.
Seeds are the only intervals for rules 1 and 2; rule 3 reports its own band and its coverage over seeds. Where a rule
is right by construction in a scenario, the page says so.

What it is worth: a declared US$500,000 a month of paid media split across the four paid channels in proportion to
their last-touch shares; the spend moved by a rule's share errors is half the sum of the absolute differences between
its paid split and the true one, times the budget. An assumption, not a measured saving.

## 7. Predictions (before any run)

1. In the realistic scenario the deterministic rule overcounts users by more than 20% in every seed.
2. In the realistic scenario rule 2 at 0.9 cuts the deterministic rule's count error by at least half, and makes at
   least 3 times its merges per 100 users.
3. In the realistic scenario rule 3's band holds the true user count in at least 8 of 10 seeds.
4. With device ids withheld, paid social's last-touch share falls by at least 3 points under every rule, including
   a perfect stitch on the recorded rows.
5. With the migration alone, the deterministic rule's count error rises by at least 10 points over the baseline.
6. In the realistic scenario rule 2's own estimate of its link precision is more than 5 points above the true
   precision.

## 8. What would change the conclusion

- If the order of rules 1 and 2 by count error in the realistic scenario flips in some seeds, the page says the
  ranking does not hold and gives the count of seeds.
- If rule 3's band misses the truth in more than 2 of 10 seeds, the page leads with that: a band is honest only if it
  holds the truth.
- If no threshold keeps both merges and splits under 5 per 100 users in the realistic scenario, the page says no
  threshold fixes it.
- Moving the assumed rates (household share of devices, the family A share, the withdrawal share) is out of scope of
  this round; the page says which of them drive the result and that they were not swept.

## 9. Checks

- Unit tests on small tables written into the test code: connected components, the merge and split counts (their identity with the
  count error), last touch and position credit, the consent guard with a planted identifier, the migration re-key.
- A seeded replay test rebuilds the results file and the page from the stored per-run aggregates and compares bytes,
  with the headline numbers pinned; one small seeded end-to-end run checks the pipeline on the generator.
- A number check ties every number on the page to the results file, with a planted number as its positive control.

## Amendment 1: a second probabilistic model, weights learnt without labels

Declared after the code ran on one development seed (100, not a reported seed) and before seeds 0 to 9 ran. On that
seed the model of section 4 learnt match and non-match probabilities close together on every feature, because the
deterministic rule's labelled matches are mostly one logged-in person's different devices and its labelled non-matches
are household members and office mates; and its prior, the labelled match share, sat far above the match share among
the pairs it scores. Rules 2 and 3 above stay exactly as declared and are reported as the main arms. Two arms are
added beside them, built for this weakness and labelled so on the page:

- **Rule 2b:** the same candidates and features; the match and non-match probabilities and the prior are estimated by
  expectation maximisation over every scored pair (the textbook unsupervised Fellegi-Sunter fit, features independent
  given match status), started from section 4's label-trained values and run for at most 200 iterations or until the
  log-likelihood gains less than 1e-9. A pair links at a posterior of 0.9, with the same login guard.
- **Rule 3b:** rule 3's band drawn from rule 2b's posteriors.

Predictions for the added arms, before any run:

7. In the realistic scenario rule 2b's estimated prior is below rule 2's labelled prior in every seed.
8. In the realistic scenario rule 3b's band holds the true user count in more seeds than rule 3's.

## Amendment 2: wording only

Section 9's description of the unit-test tables was reworded to "small tables written into the test code", which is
what they are: fixed tables in the test source, checked by code. No check, measure or result changed.

## Amendment 3: a small sweep of two assumed rates, added after the results were read

Declared after seeds 0 to 9 had been read and after an independent review asked how far one set of assumed rates
carries the headline. Nothing above changes, and the frozen per-run files stay as they are. Added runs, with all four
losses together (the realistic scenario) on the same seeds 0 to 9 and the same rules:

- the share of people who decline consent at their first visit: 4%, 8% (the declared value) and 16%;
- the capped family's share of phone browsers: 30%, 55% (the declared value) and 80%;
- every pair of the two, so 9 settings x 10 seeds. Every other rate stays as declared. The 8% and 55% setting
  reproduces the main runs and is checked against them.

Reported per setting: users counted per true user by the deterministic rule and by the probabilistic rule at 0.9,
each in two ways (every key a user, a distinct-id count; and identified users only, without the one-visit keys left
after a declined or withdrawn consent), plus the band's coverage of the true count. The page gives the range over the
9 settings and 10 seeds, labelled as added after the results.

Also recomputed from the same seeds, for the page's account of the band: the share of true users who declined consent,
next to the band's estimate of the people behind one-visit keys.
