Propensity scores and inverse probability weights

Today let's look at what happens when a business hands out an offer unevenly, and work out how to still get a fair read on whether that offer worked.

Meridian Fitness has 300 new members. In each member's first month, the gym recorded how many times they visited: that's month1_visits. Then, leaning toward the members who had already visited more, Meridian offered some of them a free one-on-one trainer session. Four months later, the gym recorded month4_visits: how many times that same member visited in month 4.

Here are 7 of those 300 members, chosen to span the full range of month-1 visits.

Look at month1_visits next to offered. There is a clear lean: the members who visited 14 or 15 times both got the offer, and the members who visited only once or three times both did not. But it is not a strict rule. Member 288 visited only twice, yet got the offer anyway.

So before the session ever happened, were these members already different from each other, just based on how often they used to show up?

Why comparing the two groups directly is unfair

The 7 spotlight members hinted at something: members who visited more in month 1 were also more likely to get offered the session. That same month1_visits also affects how much a member visits in month 4, offer or no offer, since people who show up a lot tend to keep showing up. 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 offered members to not-offered members directly mixes the session's real effect together with this confounder's effect, and there is no way to tell how much of the gap is which.

Let's build the full 300-member dataset and compute that naive gap for real.

RInteractive R
# Build the 300-member data and compute the naive gap in month4_visits set.seed(42) n <- 300 month1_visits <- pmin(rpois(n, 7), 20) offered <- rbinom(n, 1, plogis(-2.5 + 0.3 * month1_visits)) month4_visits <- 10 + 3 * offered + 0.4 * month1_visits + rnorm(n, 0, 2) members <- data.frame(member = seq_len(n), month1_visits, offered, month4_visits) naive_gap <- mean(members$month4_visits[members$offered == 1]) - mean(members$month4_visits[members$offered == 0]) round(naive_gap, 2) #> [1] 3.65

  

rpois(n, 7) draws 300 random counts that scatter around a typical value of 7, one for each member's month-1 visits, and pmin(..., 20) caps that count at 20 so nobody's number looks impossible. Then rbinom(n, 1, p) flips a weighted coin for each member to decide offered, 1 or 0, where the chance of landing on 1 is plogis(-2.5 + 0.3 * month1_visits), a formula that climbs the more a member already visited.

month4_visits is then built directly from a formula: 10, plus 3 if the member was offered, plus 0.4 times month1_visits, plus some random noise from rnorm(n, 0, 2) standing in for everything else that nudges a visit count up or down. Because we built it ourselves, we know the session's true effect is exactly 3, the number we used to generate the data. In the real world you would never know that true number. Here, knowing it lets us check whether a method's estimate actually lands close to it.

That naive gap comes out to 3.65, not 3. It overstates the session's real effect, because the members who got offered were already the kind of members who visited more, even before the session happened.