| Hospital | Treatment | Patients | Successes | Failures | Success rate |
|---|---|---|---|---|---|
| X | A | 90 | 80 | 10 | 0.889 |
| X | B | 10 | 9 | 1 | 0.9 |
| Y | A | 10 | 1 | 9 | 0.1 |
| Y | B | 90 | 30 | 60 | 0.333 |
ST201 - Data analysis
Can a treatment appear more successful overall, even when it performs worse in every hospital?
By the end of this lecture, you should be able to:

So far, we have considered the relationship between two categorical variables.
What happens when we introduce a third categorical variable?
Suppose we want to compare two medical treatments
We start with the initial question
Is Treatment A more successful than Treatment B?
Now suppose we also know which hospital treated each patient.
Our question becomes:
Does the treatment comparison look the same within each hospital?
The relationship between two variables can look different when we examine it within levels of a third variable.
We observe patients receiving Treatment A or Treatment B in two hospitals.
Each patient either experiences treatment success or treatment failure.
We record:
We will compare success rates first overall and then within each hospital.
| Hospital | Treatment | Patients | Successes | Failures | Success rate |
|---|---|---|---|---|---|
| X | A | 90 | 80 | 10 | 0.889 |
| X | B | 10 | 9 | 1 | 0.9 |
| Y | A | 10 | 1 | 9 | 0.1 |
| Y | B | 90 | 30 | 60 | 0.333 |
A success rate is the proportion of patients who experienced success:
\[ \text{Success rate} = \frac{\text{Number of successes}}{\text{Number of patients}} \]
What happens if we combine all patients receiving each treatment?
| Treatment | Patients | Successes | Success rate |
|---|---|---|---|
| A | 100 | 81 | 81.0% |
| B | 100 | 39 | 39.0% |
Treatment A has an overall success rate of 81%, compared with 39% for Treatment B.
Treatment A is used mainly in Hospital X. Treatment B is used mainly in Hospital Y
| Hospital | Treatment | Patients | Successes | Success rate |
|---|---|---|---|---|
| X | A | 90 | 80 | 88.9% |
| X | B | 10 | 9 | 90.0% |
| Y | A | 10 | 1 | 10.0% |
| Y | B | 90 | 30 | 33.3% |
Treatment B has a higher success rate in both hospitals.
We have found two different conclusions:
Treatment A appears better
Treatment B performs better in both
Simspons Paradox

Simpson’s paradox occurs when an association between two variables reverses direction, or otherwise changes substantially, after considering a third variable.
In our example:
The third variable is hospital
The two treatments are used in different proportions across the hospitals.
The overall success rate therefore reflects both:
The patients receiving the two treatments are not distributed equally across hospitals
A lurking variable is a variable omitted from an initial comparison that can help explain the observed relationship.
For example:
Other examples might include:
A third variable can exaggerate, weaken, hide or reverse an observed association.
Sometimes we want to compare outcomes using odds rather than proportions.
If the probability of success is \(p\), the odds of success are
\[ \text{Odds} = \frac{p}{1 - p} \]
For example, if the probability of success is 0.75:
\[ \text{Odds} = \frac{0.75}{1 - 0.75} = 3 \]
Or more simply the odds are 3:1
| Probability | Odds |
|---|---|
| 0.20 | 0.20 / 0.80 = 0.25:1 |
| 0.50 | 0.50 / 0.50 = 1:1 |
| 0.75 | 0.75 / 0.25 = 3:1 |
| 0.90 | 0.90 / 0.10 = 9:1 |
When an event is common, its odds can be substantially larger than its probability.
An odds ratio (OR) compares the odds between two groups
\[ \text{OR} = \frac{\text{Odds in Group 1}}{\text{Odds in Group 2}} \]
Interpretation
An odds ratio of 2 means that the odds in Group 1 are twice those in Group 2.
It does not necessarily mean that the probability is twice as high.
Suppose we compare two treatments
| Success | Failure | |
|---|---|---|
| Treatment A | (A) | (B) |
| Treatment B | (C) | (D) |
The odds ratio is
\[ OR = \frac{a/b}{c/d} = \frac{ad}{bc} \]
We call this a cross-product ratio
| Success | Failure | |
|---|---|---|
| Treatment A | 80 | 10 |
| Treatment B | 60 | 40 |
\[ \text{Odds}_A = \frac{80}{10}=8 \]
\[ \text{Odds}_B = \frac{60}{40}=1.5 \]
\[ OR = \frac{8}{1.5} \approx 5.33 \]
The odds of success are approximately 5.33 times as high for Treatment A as for Treatment B in this example.
We can calculate:
These are different summaries of the association between treatment and success.
The key question becomes:
Do the treatment odds ratios tell the same story before and after stratification?
| Comparison | Odds Ratio |
|---|---|
| Overall | 6.668 |
| X | 0.889 |
| Y | 0.222 |
The odds ratios also reverse direction: the overall comparison favours A, whereas both hospital-specific comparisons favour B.
We can describe the two approaches using statistical terminology.
Marginal association
Conditional association
All patients are combined.
\[ P(\text{Success}\mid \text{Treatment}) \]
Patients are compared within hospital.
\[ P(\text{Success}\mid \text{Treatment, Hospital}) \]
Next time you compare two groups, ask: could a third variable change the conclusion?
We now move to a real example.
The UC Berkeley admissions data record university applications by:
Our initial question is:
Were male and female applicants admitted at different rates?
We will then consider whether the department applied to changes our interpretation.