10.3. Causality#
A causal claim says that changing one factor, such as making a retention call, changes an outcome, such as renewal. This is causality, and it is harder to establish than an association. A well-run randomized experiment uses chance to assign participants to a treatment group and a control group. That design supports a causal interpretation because assignment does not systematically depend on participants’ pre-existing characteristics. The groups can still differ by chance, which is why you compare the observed difference with a randomization distribution.
A causal conclusion also depends on how the experiment was conducted. Missing outcomes, inconsistent treatment delivery, or one participant’s treatment changing another participant’s outcome can complicate interpretation. Random assignment is a design tool, not a guarantee that every source of bias has vanished.
Chapter 10 uses the same permutation workflow three times. The study design determines how far you can take the conclusion.
Section |
Comparison |
Statistic and direction |
What the design supports |
|---|---|---|---|
Checkout A vs. checkout B (randomized) |
B minus A conversion rate; upper tail |
Evidence that the checkout version changed conversion for the visitors in the test. |
|
Weekend vs. weekday visits (observational) |
Weekend minus weekday conversion rate; upper tail |
An association under the null model; not an effect of the weekend, because customers chose when to shop. |
|
10.3 (this section) |
Retention call vs. no call (randomized) |
Absolute difference in renewal rates; both tails |
Evidence of a treatment effect for the customers in the trial. |
This section explains why the randomized cases support causal language and the observational case does not. It uses a retention trial to introduce potential outcomes, runs a two-sided test by re-randomizing, and ends with what a careful analyst can and cannot claim. Run the demonstration cells in order.
10.3.1. A Randomized Retention Trial#
A subscription software company wants to reduce cancellations. Its analytics team flags 80 customers who are likely to cancel at the next renewal date. The retention manager wants to know whether a phone call from an account manager makes these customers more likely to renew. Calls take staff time, so the company will only roll the program out if the evidence is convincing.
The team runs a randomized controlled trial (also called an RCT): a study in which a chance process assigns each participant to the treatment group or the control group. Here the chance process is a random draw: 40 of the 80 flagged customers are chosen to receive a call (the treatment group), and the other 40 receive no call (the control group). After the renewal date, the team records whether each customer renewed.
The table below rebuilds the trial’s 80 rows. The counts are 28 renewals among the 40 called customers and 17 renewals among the 40 customers who were not called. (The company and its trial are hypothetical, made up for this example.)
group = ['call'] * 40 + ['no call'] * 40
renewed = [1] * 28 + [0] * 12 + [1] * 17 + [0] * 23
trial = pd.DataFrame({'group': group, 'renewed': renewed})
trial.sample(6, random_state=3)
| group | renewed | |
|---|---|---|
| 61 | no call | 0 |
| 57 | no call | 0 |
| 77 | no call | 0 |
| 6 | call | 1 |
| 45 | no call | 1 |
| 8 | call | 1 |
The sample(6) method (listed in the table in DataFrames) returns six randomly chosen rows, a quick way to preview a table whose rows are sorted by group. The argument random_state=3 fixes the random choice so that everyone sees the same six rows.
Each row is one customer. The group column records the random assignment and renewed is 1 if the customer renewed and 0 if not. The mean of a 0/1 column is a proportion, so groupby gives the renewal rate in each group.
rates = trial.groupby('group')['renewed'].agg(['count', 'sum', 'mean'])
rates.columns = ['customers', 'renewals', 'renewal_rate']
print(rates)
observed_gap = rates.loc['call', 'renewal_rate'] - rates.loc['no call', 'renewal_rate']
print('Observed difference (call minus no call):', round(observed_gap, 3))
customers renewals renewal_rate
group
call 40 28 0.700
no call 40 17 0.425
Observed difference (call minus no call): 0.275
The called customers renewed at a rate of 0.70 and the others at 0.425, a difference of 0.275, or 27.5 percentage points. The question for the rest of the section is whether a gap this large could plausibly come from the random assignment alone.
### Exercise: Assign Customers at Random
# Ten flagged customers are in customers. Assign five of them to receive a call.
# 1. Use rng.choice(customers, size=5, replace=False) to choose the called group.
# 2. The rest form the control group.
# 3. Print each group's IDs in sorted order, separated by commas.
# Print exactly:
# Called: C02, C03, C05, C07, C08
# Not called: C01, C04, C06, C09, C10
import numpy as np
rng = np.random.default_rng(10)
customers = np.array(['C01', 'C02', 'C03', 'C04', 'C05', 'C06', 'C07', 'C08', 'C09', 'C10'])
### Your code starts here.
### Your code ends here.
Called: C02, C03, C05, C07, C08
Not called: C01, C04, C06, C09, C10
10.3.2. Potential Outcomes#
To say that a call caused a customer to renew, you need to compare two situations for the same customer: what happens with a call, and what happens without one. Each customer therefore has two potential outcomes: whether the customer would renew if called, and whether the customer would renew if not called.
The difficulty is that each customer is assigned to only one condition. You observe the outcome under the condition the customer actually received, and the other outcome is never seen. This is sometimes called the fundamental problem of causal inference. The table below shows five customers from the trial. A question mark marks the potential outcome that was not observed.
five = pd.DataFrame({
'customer': ['Ana', 'Ben', 'Cruz', 'Dee', 'Eli'],
'assigned': ['call', 'no call', 'call', 'no call', 'call'],
'renews if called': ['yes', '?', 'no', '?', 'yes'],
'renews if not called': ['?', 'no', '?', 'yes', '?'],
})
five
| customer | assigned | renews if called | renews if not called | |
|---|---|---|---|---|
| 0 | Ana | call | yes | ? |
| 1 | Ben | no call | ? | no |
| 2 | Cruz | call | no | ? |
| 3 | Dee | no call | ? | yes |
| 4 | Eli | call | yes | ? |
Ana, Cruz, and Eli were called, so only their “renews if called” outcome is known. Ben and Dee were not called, so only their “renews if not called” outcome is known. No customer has both, so you cannot read any one customer’s causal effect from the data.
Randomization offers a way around this. Because chance decides who is called, the called group and the uncalled group are alike on average in every respect, including how likely each customer would have been to renew without a call. The uncalled customers then show what the called customers would have done without the call, and the difference between the group rates estimates the average treatment effect (the average, across customers, of the call’s effect on renewal).
### Exercise: Identify the Missing Outcome
# A customer is randomly assigned to receive a retention call and then renews.
# Can you observe whether that same customer would have renewed without the call?
# Print observed or unknown.
# Print exactly:
# unknown
### Your code starts here.
### Your code ends here.
unknown
10.3.3. The Hypotheses#
For this randomization test, use a sharp null hypothesis (often called Fisher’s exact null hypothesis) of no effect: each customer’s renewal outcome would be the same whether or not the customer received a call. It is called sharp because it specifies the missing potential outcome for every customer: the unseen outcome equals the seen one. Under that null, the observed zeros and ones stay fixed while the random assignment varies.
Null Hypothesis: The retention call has no effect on any customer’s renewal. Differences between the two randomized groups arise from assignment alone.
Alternative Hypothesis: The retention call affects renewal for some customers. The observed difference in group renewal rates can provide evidence against the no-effect null.
Equal average outcomes are a weaker claim than no effect for every customer: a call might persuade some customers to stay and annoy others into leaving, and the two effects could cancel. The simple shuffle below represents the stronger no-effect model. A test based on a rate difference may not detect effects that cancel in the average.
Use a two-sided statistic, the absolute difference in renewal rates, as in the traffic-split test of 9.3. The direction is two-sided because either an increase or a decrease in renewal would matter to the company: a call that drove customers away would be just as important to find. Choose this direction and the significance level (0.05) before looking at the result. For a question specifically about improvement, state a one-sided alternative in advance and keep the sign of the call-minus-no-call difference.
Under the sharp null, any random subset of 40 of the 80 customers could have received a call and the remaining 40 no call. Permuting the labels preserves those group sizes and the 80 observed outcomes. This is the same computation used in A/B Testing; here, the real random assignment is what justifies the reference distribution.
### Exercise: One-Sided or Two-Sided Statistic
# In a pilot, called customers renewed at 0.55 and uncalled customers at 0.60.
# 1. Compute the one-sided statistic, call minus no call (keep the sign).
# 2. Compute the two-sided statistic, the absolute difference.
# 3. Print both, rounded to 2 decimals.
# Print exactly:
# One-sided statistic: -0.05
# Two-sided statistic: 0.05
call_rate = 0.55
no_call_rate = 0.60
### Your code starts here.
### Your code ends here.
One-sided statistic: -0.05
Two-sided statistic: 0.05
10.3.4. Testing by Re-randomizing#
The test statistic is the absolute difference in renewal rates between the two groups. Taking the absolute value counts a large gap in either direction as evidence against the null. The function below computes it from a list of group labels and the 0/1 outcomes.
def renewal_gap(labels, outcomes):
# Absolute difference in renewal rates between the two groups
return abs(outcomes[labels == 'call'].mean() - outcomes[labels == 'no call'].mean())
labels = trial['group'].to_numpy()
outcomes = trial['renewed'].to_numpy()
observed = renewal_gap(labels, outcomes)
print('Observed statistic:', round(observed, 3))
Observed statistic: 0.275
10.3.4.1. One Re-randomization#
A re-randomization repeats the random assignment on the same 80 customers: it shuffles the call and no call labels and recomputes the statistic. If the call has no effect, the shuffled assignment is as plausible as the real one, and each customer keeps the same outcome.
rng = np.random.default_rng(1003)
shuffled_labels = rng.permutation(labels)
print('Called customers in the shuffle:', np.sum(shuffled_labels == 'call'))
print('Renewals in the shuffle (always 45):', outcomes.sum())
print('Statistic from this re-randomization:', round(renewal_gap(shuffled_labels, outcomes), 3))
Called customers in the shuffle: 40
Renewals in the shuffle (always 45): 45
Statistic from this re-randomization: 0.125
The shuffled assignment still has 40 customers in each group and the same 45 renewals in total (28 plus 17); only the pairing of labels to customers changed. This single shuffle produced a gap of 0.125, well below the observed 0.275. One shuffle says little by itself, so repeat it many times.
10.3.4.2. Many Re-randomizations#
Now repeat the shuffle 10,000 times and record the statistic each time. The collection of values is the randomization distribution of the statistic under the null: it shows how large a gap in renewal rates can arise from assignment alone.
rng = np.random.default_rng(2026)
simulated = np.empty(10000)
for i in range(10000):
simulated[i] = renewal_gap(rng.permutation(labels), outcomes)
print('Largest simulated gap:', round(simulated.max(), 3))
print('Typical (median) simulated gap:', round(np.median(simulated), 3))
Largest simulated gap: 0.425
Typical (median) simulated gap: 0.075
fig, ax = plt.subplots(figsize=(7, 3.8))
ax.hist(simulated, bins=np.arange(-0.0125, 0.5, 0.025),
color='tab:blue', alpha=0.8, edgecolor='white')
ax.axvline(observed, color='tab:red', lw=3,
label=f'Observed gap = {observed:.3f}')
ax.set_xlabel('Absolute difference in renewal rates (call vs. no call)')
ax.set_ylabel('Number of re-randomizations')
ax.set_title('A gap of 0.275 is unusual if the call has no effect')
ax.legend()
plt.show()
Most re-randomizations give gaps well under 0.2. The observed gap sits far out in the right tail. The p-value is the fraction of simulated statistics at least as large as the observed one. The values are rounded to four decimals first so that tiny floating-point differences do not decide whether a tied value counts.
p_value = np.mean(np.round(simulated, 4) >= np.round(observed, 4))
print('Simulated tail fraction (two-sided p-value):', p_value)
Simulated tail fraction (two-sided p-value): 0.0207
The two-sided p-value is about 0.02, below the 0.05 level chosen in advance. If the call had no effect on any customer, a random assignment would produce a gap this large in either direction only about 2 times in 100. That is evidence against the no-effect null, and the higher renewal rate in the called group points to a beneficial call. Because the p-value comes from a simulation, a different seed would give a slightly different value near 0.02.
10.3.4.3. Practice#
### Exercise: One Re-randomization
# Twelve flagged customers: the first six were called and the rest were not.
# Their renewal outcomes (1 = renewed) are in `outcomes_small`.
# 1. Create a generator with seed 5 and shuffle `labels_small` once.
# 2. Print the number of renewals among customers labelled 'call' after the shuffle.
# 3. Print the total number of renewals, which a shuffle never changes.
# Print exactly:
# Renewals in the shuffled call group: 3
# Total renewals: 7
import numpy as np
labels_small = np.array(['call'] * 6 + ['no call'] * 6)
outcomes_small = np.array([1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0])
### Your code starts here.
### Your code ends here.
Renewals in the shuffled call group: 3
Total renewals: 7
### Exercise: Interpret a Two-Sided Distance
# The statistic is the absolute difference in renewal proportions.
# Compute the simulated tail fraction, including a result equal to observed.
# 1. Use np.mean on a comparison of `simulated_small` with `observed_small`.
# 2. Print the result with the label shown.
# Print exactly:
# Tail fraction: 0.4
import numpy as np
observed_small = 0.3
simulated_small = np.array([0.0, 0.1, 0.3, 0.4, 0.2])
### Your code starts here.
### Your code ends here.
Tail fraction: 0.4
10.3.5. From Evidence to a Causal Claim#
The randomized design and small p-value provide evidence that the call affected renewal for the customers in this trial, assuming the trial was conducted as described. The called group’s renewal rate is higher, so the estimated direction is beneficial. The absolute-distance p-value alone would not tell you that direction; you read it from the two group rates.
Why randomization removes confounding by design. In Comparing Groups Without Random Assignment, customers chose when to shop, and weekend visits were spread over the months differently from weekday visits. The month was a confounder: a variable whose effect gets mixed into the treatment comparison. Here, no customer chose a call and no account manager picked who got one. A random draw assigned the calls, so a customer’s loyalty, contract size, or enthusiasm cannot be related to who was called, except by chance. The test accounts for chance differences. Random assignment prevents systematic allocation; it does not force two groups of 40 to be identical.
Direction and size. A significant result says a difference is unlikely to be chance. It does not say how large the effect is. The estimated effect is 27.5 percentage points. A difference stated in practical units like this is the effect size, and it is what a manager weighs against the cost of the program. With only 80 customers that estimate is imprecise, and Estimation shows how to attach an interval to it.
Generalization. Random assignment answers a causal question for the customers in the trial. Random sampling answers a separate question: to whom can you generalize? These 80 customers were flagged as likely to cancel. The trial supports a conclusion about flagged customers like them, not about all subscribers, who may be happy to renew without a call, or about customers flagged at another company or in another year.
Interference. The comparison assumes no interference: one customer’s treatment does not change another customer’s outcome. That is reasonable for individual phone calls. It would fail if called customers told colleagues at the same firm, or if the account manager spent so much time on calls that the uncalled customers received worse service.
Comparable follow-up. The two groups must be tracked the same way. If cancelled accounts in one group were dropped from the data, the comparison would be biased even though assignment was random.
Blinding and placebos. Knowing which group you are in can change behavior. In a drug trial, the control group often receives a placebo, an inactive treatment that looks like the real one, and blinding keeps participants, and often the staff who measure outcomes, from knowing who received which. A phone call cannot be disguised, so these customers know whether they were called. Renewal comes from billing records, which knowing about the call cannot change, so the lack of blinding matters less here than it would for an outcome such as a satisfaction rating.
A business reading: cost per retained customer. Suppose each call costs the company $60 in staff time. Forty calls cost $2,400. If the no-call renewal rate is the best guide to what the called customers would have done, then about 17 of the 40 called customers (42.5% of 40) would have renewed anyway, so the calls added 11 renewals. The extra renewals are the ones the program paid for.
call_cost = 60
n_called = 40
total_cost = call_cost * n_called
expected_without_calls = n_called * rates.loc['no call', 'renewal_rate']
extra_renewals = rates.loc['call', 'renewals'] - expected_without_calls
print('Total cost of calls: $', total_cost)
print('Extra renewals attributed to the calls:', extra_renewals)
print('Cost per extra renewal: $', round(total_cost / extra_renewals, 2))
Total cost of calls: $ 2400
Extra renewals attributed to the calls: 11.0
Cost per extra renewal: $ 218.18
Each extra renewal cost about $218. Whether that is worth it depends on what a renewal is worth. If an average renewal brings in more than $218 in profit, the program pays for itself on these numbers; if not, it does not, however significant the p-value. Statistical significance answers whether there is an effect; the cost comparison answers whether the effect is worth buying. The $218 is also an estimate with the same imprecision as the 27.5-point gap.
Sample size and power. The sample size is the number of observations in a study or group, here 40 customers per group. Statistical power is the chance of detecting an effect of a specified size with a specified test. A trial of 80 customers can miss a real but modest effect, and it gives an imprecise estimate of any effect it does find. A larger sample improves precision under otherwise comparable conditions, but it cannot repair biased assignment or unequal follow-up.
What failing to reject means. Suppose the p-value had been 0.30. That would be insufficient evidence of an effect, not proof of no effect. With 80 customers, a modest real benefit could easily produce a p-value like that. The right report would be “this trial was too small to tell”, not “calls do not work”.
### Exercise: Cost per Extra Renewal
# A different retention program called 50 flagged customers at $40 per call.
# 30 of the 50 called customers renewed. In the control group, 20 of 50 renewed.
# 1. Compute the total cost of the calls.
# 2. Compute the extra renewals: called renewals minus the 20 expected
# without calls (the control renewal count, since both groups have 50).
# 3. Print the cost per extra renewal.
# Print exactly:
# Total cost: 2000
# Extra renewals: 10
# Cost per extra renewal: 200.0
n_called_ex = 50
cost_per_call = 40
renewed_called = 30
renewed_control = 20
### Your code starts here.
### Your code ends here.
Total cost: 2000
Extra renewals: 10
Cost per extra renewal: 200.0
10.3.6. Combining Several Small Pilots#
Companies often run several small pilots rather than one large trial. Suppose the retention program was also tried in four regional offices. Each office randomly assigned its flagged customers to a call or no call. The offices are small, so no single pilot is conclusive by itself. The table below records how many customers in each group renewed.
pilots = pd.DataFrame({
'region': ['North', 'South', 'East', 'West'],
'called': [12, 16, 10, 14],
'called_renewed': [9, 11, 7, 10],
'not_called': [12, 16, 10, 14],
'not_called_renewed': [6, 8, 4, 7],
})
pilots['called_rate'] = pilots['called_renewed'] / pilots['called']
pilots['not_called_rate'] = pilots['not_called_renewed'] / pilots['not_called']
pilots['difference'] = pilots['called_rate'] - pilots['not_called_rate']
pilots.round(3)
| region | called | called_renewed | not_called | not_called_renewed | called_rate | not_called_rate | difference | |
|---|---|---|---|---|---|---|---|---|
| 0 | North | 12 | 9 | 12 | 6 | 0.750 | 0.5 | 0.250 |
| 1 | South | 16 | 11 | 16 | 8 | 0.688 | 0.5 | 0.188 |
| 2 | East | 10 | 7 | 10 | 4 | 0.700 | 0.4 | 0.300 |
| 3 | West | 14 | 10 | 14 | 7 | 0.714 | 0.5 | 0.214 |
All four pilots point the same way: the called customers renewed at a higher rate in every region, by between about 19 and 30 percentage points. But each pilot has only 20 to 32 customers. To see how little each one can say alone, run the same re-randomization test on each pilot separately. The function below builds each pilot’s 0/1 outcomes and counts how often a shuffle produces a gap at least as large as the one observed. (In the example below, itertuples() visits each row of pilots in turn, so r.called is that row’s called value.)
### a function for p_value
### pilot_outcomes is the list of 0/1 renewal results, one per customer,
### rebuilt from the summary counts.
def pilot_p_value(called, called_renewed, not_called, not_called_renewed, seed):
pilot_rng = np.random.default_rng(seed)
pilot_labels = np.array(['call'] * called + ['no call'] * not_called)
pilot_outcomes = np.array([1] * called_renewed +
[0] * (called - called_renewed) +
[1] * not_called_renewed +
[0] * (not_called - not_called_renewed))
obs = renewal_gap(pilot_labels, pilot_outcomes)
sims = np.array([renewal_gap(pilot_rng.permutation(pilot_labels),
pilot_outcomes) for _ in range(5000)])
return np.mean(np.round(sims, 4) >= np.round(obs, 4))
pilots['p_value'] = [
pilot_p_value(r.called, r.called_renewed, r.not_called,
r.not_called_renewed, seed=10 + i)
for i, r in enumerate(pilots.itertuples()) ### named tuple per row
]
print(pilots[['region', 'difference', 'p_value']].round(3))
region difference p_value
0 North 0.250 0.402
1 South 0.188 0.458
2 East 0.300 0.365
3 West 0.214 0.435
No pilot reaches the 0.05 level on its own: every p-value is well above it. Read one at a time, each pilot would lead to “not enough evidence”. Yet the four differences are all positive and similar in size, which would be a surprising coincidence if the call did nothing.
Combining studies is the idea of pooling the results of several studies of the same question to get a more precise answer. Formal versions are called meta-analysis. The simplest version here pools the raw counts, as if the four pilots were one trial of 52 called and 52 uncalled customers, and runs the same test.
pooled = pilots[['called', 'called_renewed', 'not_called', 'not_called_renewed']].sum()
pooled_called_rate = pooled['called_renewed'] / pooled['called']
pooled_not_called_rate = pooled['not_called_renewed'] / pooled['not_called']
print('Pooled called rate: ', round(pooled_called_rate, 3))
print('Pooled not-called rate:', round(pooled_not_called_rate, 3))
print('Pooled difference: ', round(pooled_called_rate - pooled_not_called_rate, 3))
pooled_p = pilot_p_value(pooled['called'], pooled['called_renewed'],
pooled['not_called'], pooled['not_called_renewed'], seed=99)
print('Pooled p-value: ', round(pooled_p, 3))
Pooled called rate: 0.712
Pooled not-called rate: 0.481
Pooled difference: 0.231
Pooled p-value: 0.028
Pooled, the called customers renewed at 0.712 and the others at 0.481, a gap of about 23 percentage points, and the p-value drops to about 0.03, below the 0.05 level (the individual p-values were all 0.36 or higher). Individually the pilots were too small to settle the question; together they give a clearer answer. The pooled gap is also in the neighborhood of the main trial’s 27.5 points, which adds confidence that the original result was not a fluke.
Combining studies has cautions:
The studies must be comparable. Pilots that used different customer groups, different scripts for the call, or different definitions of “renewed” are not measuring the same thing, and pooling their counts hides that. Pooling raw counts is also only safe when each pilot gave calls to roughly half of its customers, as these did. Real meta-analyses weight each study and check how much they disagree.
Publication of only good results. If only the pilots that worked get reported, pooling the reported ones overstates the effect. Combine all the pilots the company ran, including the failures, not the ones someone chose to present.
Each study still needs sound design. Pooling many biased studies gives a precise but wrong answer. Randomization within each pilot is what makes the pooled comparison causal.
### Exercise: Pool Two Pilots
# Two small pilots randomly assigned customers to a call or no call.
# Pilot 1: 7 of 10 called customers renewed; 4 of 10 not called renewed.
# Pilot 2: 8 of 12 called customers renewed; 5 of 12 not called renewed.
# 1. Compute each pilot's difference in renewal rates (called minus not called).
# 2. Pool the counts and compute the pooled difference.
# 3. Print all three differences rounded to 3 decimals.
# Print exactly:
# Pilot 1: 0.3
# Pilot 2: 0.25
# Pooled: 0.273
### Your code starts here.
### Your code ends here.
Pilot 1: 0.3
Pilot 2: 0.25
Pooled: 0.273
10.3.7. Section Practice#
Use what you learned about randomized trials and causal claims in the exercise below.
### Exercise: Practice Causality
# A retail chain randomly assigned 30 of its 60 stores to a new staff-training
# program (treatment); the other 30 had no training (control). It recorded which
# stores met their quarterly sales target. A re-randomization test of the
# absolute difference gave a two-sided p-value of 0.04.
# 1. Compute the proportion of stores that met the target in each group.
# 2. Compute the difference, treatment minus control.
# 3. If the study was randomized and the p-value is below 0.05, print
# "Claim: the training raised the target rate for these stores";
# otherwise print "Claim: no causal conclusion".
# Print exactly:
# Treatment: 0.6
# Control: 0.3
# Difference: 0.3
# Claim: the training raised the target rate for these stores
import pandas as pd
stores = pd.DataFrame({
'group': ['treatment', 'control'],
'met_target': [18, 9],
'missed_target': [12, 21],
})
randomized = True
p_value = 0.04
### Your code starts here.
### Your code ends here.
Treatment: 0.6
Control: 0.3
Difference: 0.3
Claim: the training raised the target rate for these stores