Matching and what it throws away
Today let's look at what happens when you compare two groups by pairing each one up with its closest match, instead of fitting a model over everyone, and see exactly what that pairing leaves out.
Fernview runs a free tier with 200 users. In each user's first week, Fernview recorded how many times they opened the app: that's sessions_week1. Then, leaning toward the users who had fewer sessions in week 1, Fernview sent some of them a re-engagement reminder. Three weeks later, Fernview recorded sessions_week4: how many times that same user opened the app in week 4.
Here are 7 of those 200 users, chosen to span the full range of week-1 sessions.
Look at sessions_week1 next to reminder. Users 24 and 3, who had only 1 and 2 sessions in week 1, both got the reminder. User 116, who already had 13 sessions, did not. But it is not a strict rule: user 42 had 10 sessions in week 1, well above average, and still got the reminder.
So before the reminder ever landed, were these users already different from each other, just based on how much they were already using the app?
Why comparing reminder users to everyone else is unfair
The 7 spotlight users hinted at something: users with fewer sessions in week 1 were also more likely to get the reminder. That same sessions_week1 also affects sessions_week4 on its own, since a user who already opens the app a lot in week 1 tends to keep opening it, reminder or not. A variable like this, one that affects both who receives a treatment and the outcome you are trying to measure, is called a confounder. Comparing reminder users to non-reminder users directly mixes the reminder's real effect together with this confounder's effect, and there is no way to tell how much of the gap is which.
This is simulated data, so the real effect of the reminder on sessions_week4 is known by construction: 2 sessions. A real dataset would never hand you that number. Matching is one way to recover it as closely as possible, without knowing it in advance.
Let's build the full 200-user dataset and compute the naive gap for real.
pmin(rpois(n, 6), 16) draws a session count for each user from a Poisson distribution centred on 6, capped at 16 so no single user runs away with an implausible count. plogis() turns the expression inside it into a probability between 0 and 1, so reminder is a coin flip whose odds shift with sessions_week1: a user with fewer sessions in week 1 gets a higher chance of the reminder. table(users$reminder) confirms the split: 127 users with no reminder, 73 with one.
The naive gap, the plain difference in sessions_week4 between the 73 reminder users and the 127 non-reminder users, comes out to 0.53. That badly understates the true effect of 2. sessions_week1 pulls in two directions at once here: it lowers the chance a user gets the reminder, since Fernview already targets the less-engaged users, but it raises sessions_week4 on its own, since an engaged user in week 1 tends to stay engaged. Part of the real +2 effect gets cancelled out by the groups' pre-existing difference in sessions_week1.