AI Computer Institute
Expert-curated CS & AI curriculum aligned to CBSE standards. A bharath.ai initiative. About Us

Introduction to Causal Inference

📚 Applied Statistics⏱️ 22 min read🎓 Grade 10
✍️ AI Computer Institute Editorial Team Updated: August 2026 CBSE-aligned · Peer-reviewed · 22 min read
Content curated by subject matter experts with IIT/NIT backgrounds. All chapters are fact-checked against official CBSE/NCERT syllabi.

Meet Radhika, who runs a small photocopy-and-stationery shop across the street from a coaching centre. Every afternoon, dozens of students stop by to print notes, buy graph paper, and photocopy old question papers. In September, she finally sets up a UPI QR code at her counter so customers can pay by scanning their phones instead of hunting for exact change. Over the next two months, her daily collections rise sharply.

Her cousin, who works at a bank, is quick to draw a conclusion: "See, accepting UPI caused your sales to jump." Radhika is not convinced. September to November is also when Diwali shopping picks up across the country, when Class 10 and 12 students are deep into board-exam revision and buying extra material, and when the coaching centre across the street runs its final pre-exam batches. Her sales might have climbed no matter what she did at the counter.

This is the puzzle at the centre of causal inference: the world constantly hands us two things that happened at the same time, but it never labels, by itself, whether one of them caused the other.

Correlation: A Pattern, Not Yet a Reason

You already know how to measure two variables moving together: correlation. If Radhika plotted her weekly UPI transaction count against her weekly sales, and both climbed through September and October, a statistician could summarise how tightly they move together with a single number, the correlation coefficient r, which ranges from -1 (perfectly opposite) through 0 (no relationship) to +1 (perfectly together). Suppose her data produced something like r = 0.9. That number alone says nothing about which variable, if either, is responsible for the other's movement. A strong correlation is a pattern crying out for an explanation. It is not the explanation.

The gap between "moves together" and "makes happen" is exactly what causal inference is built to close: the collection of tools statisticians and data scientists use to work out whether, and by how much, one thing actually causes another, rather than merely accompanying it.

The Hidden Third Variable: Confounding

To see why correlation can mislead, consider an example that shows up in almost every introductory statistics course, because it is so clean: across most cities, ice-cream sales and the number of people rescued from drowning both rise sharply in the hottest months and fall in winter. Nobody seriously believes eating ice cream causes drowning. Something else drives both patterns: rising temperature makes people buy more ice cream, and separately sends more people to pools, rivers, and beaches to cool off. Temperature is a confounding variable, a third factor that influences both the supposed cause and the supposed effect, producing a correlation between them that has nothing to do with either one causing the other. A correlation that exists only because of a shared confounder, rather than a real causal link, is called a spurious correlation.

Radhika's UPI story has the same shape. Diwali season and board-exam season are the confounders here: they push up both "the shop has just adopted UPI," since many shopkeepers switch to digital payments right before the festive rush, precisely when customer volume is about to spike anyway, and "the shop's sales are rising," without UPI itself doing all the causal work the raw correlation seems to credit it with.

This is the central danger of observational data: numbers collected simply by watching the world unfold, rather than by deliberately controlling it. Whenever the units being compared, whether shops, students, patients, or cities, differ systematically in ways connected to both the treatment and the outcome, the comparison is contaminated by confounding, and the resulting correlation cannot be read directly as causation.

The Question Causal Inference Really Asks

To make "causation" precise, statisticians frame it as a comparison between two versions of the same story. For Radhika's shop, the real causal question is not "did sales rise after UPI arrived," but: what would Radhika's November sales have been if she had adopted UPI, compared to what they would have been if she had not? Call the first number Y(1), the potential outcome under treatment, and the second Y(0), the potential outcome under no treatment. The true causal effect of UPI on her shop is the difference, Y(1) − Y(0).

The trouble appears immediately. Radhika actually adopted UPI, so we can observe Y(1), her real November sales. Nobody can rewind time, undo the adoption, and observe Y(0) for that exact same shop in that exact same November. One of the two potential outcomes is always missing. This is known as the fundamental problem of causal inference: for any single unit, a person, a shop, a student, you can observe what actually happened to them, or you can imagine what would have happened under the alternative, but never both. The unobserved alternative is called a counterfactual, because it describes a fact that runs counter to what actually happened.

Since no individual can ever supply both potential outcomes, causal inference almost always works with groups instead of single units. Rather than asking what would have happened to Radhika specifically, researchers ask: on average, across many similar shops, what is the difference between shops that adopted UPI and shops that did not? That average difference is trustworthy only if the "adopted" and "did not adopt" groups are comparable in every other way that matters for sales, which is exactly what confounding threatens.

The Gold Standard: Randomized Controlled Trials

If confounding is the problem, the cleanest fix is to remove human and circumstantial choice from who receives the treatment. In a randomized controlled trial (RCT), each unit, a patient, a user, a plot of farmland, is assigned to a treatment group or a control group purely by chance, using something equivalent to a coin flip or a random-number generator. Modern medicine relies on this design constantly: to test a new drug, researchers randomly assign volunteers to receive either the drug or a placebo, an inactive look-alike, and then compare outcomes between the two groups.

Randomization is powerful because of one simple statistical fact: when assignment is made at random, it cannot be correlated with anything about the units being assigned, not their age, not their income, not their motivation, not any confounder anyone has thought of, and not any confounder nobody has thought of either. Averaged across a large enough random split, the treatment and control groups end up statistically similar on every dimension except the one thing the experimenter deliberately changed. Any difference in outcomes between the two groups can then be credited to the treatment itself, because randomization has already balanced out everything else.

This is precisely the logic behind A/B testing, one of the most common experiments run inside Indian technology companies. When a platform like Flipkart, Swiggy, or Zomato wants to know whether a new checkout button, a new recommendation layout, or a new delivery-fee display actually changes user behaviour, rather than merely correlating with it, engineers randomly show version A to half the visiting users and version B to the other half, at the same time, under the same conditions, and compare what happens next: click-through rate, orders placed, cart abandonment. Because the split is random, any consistent difference between the two groups can be attributed to the design change itself, not to which kind of user happened to see which version. It is a randomized controlled trial running at internet scale, and it is one of the most direct applications of causal inference in the modern software industry.

When You Can't Randomize: Adjusting for Confounders

Randomization is not always available. Nobody can ethically or practically assign real students at random to "must join coaching" and "must not join coaching" for an entire academic year. Families make that decision themselves, guided by exactly the kinds of factors, such as ability, motivation, and finances, that also affect exam performance. Much of economics, education research, public health, and product analytics has to work with observational data of this kind: numbers gathered from choices people already made, not from an experiment a researcher designed.

When randomization is impossible, the next-best strategy is to measure the confounders and adjust for them statistically, comparing treated and untreated units only after accounting for the differences that were driving both the treatment decision and the outcome. One of the simplest versions of this idea is stratification: split the data into groups, or strata, that share similar values of the confounder, compare treated versus untreated within each stratum, and then combine those within-stratum comparisons into one adjusted estimate. Because everyone being compared inside a stratum already shares roughly the same value of the confounder, that confounder can no longer explain away the treated-versus-untreated difference found there.

The next section works through exactly this technique on a full numeric example.

A Worked Example: Do Coaching Classes Really Work?

Consider a Grade 10 batch of sixteen students preparing for their board exams. Eight of them entered the year as high-ability students, based on their Grade 9 marks, and eight entered as medium-ability students. Some students in each group joined a private coaching class; others did not. Their final board exam scores, out of 100, were:

  • High-ability, took coaching (6 students): 95, 96, 94, 95, 96, 94
  • High-ability, skipped coaching (2 students): 93, 91
  • Medium-ability, took coaching (2 students): 78, 76
  • Medium-ability, skipped coaching (6 students): 74, 75, 73, 76, 74, 75

Notice something uncomfortable already: most of the high-ability students chose coaching, and most of the medium-ability students did not. That imbalance is exactly the kind of confounding pattern real classrooms produce, since families who already see their child as a strong performer are often the most willing to spend on extra coaching.

First, the naive comparison: average every coached student against every non-coached student, ignoring ability completely.

  • Coached, all 8 students pooled: (95+96+94+95+96+94+78+76) / 8 = 724 / 8 = 90.5
  • Not coached, all 8 students pooled: (93+91+74+75+73+76+74+75) / 8 = 631 / 8 = 78.875
  • Naive effect of coaching: 90.5 minus 78.875 = 11.625 marks

At face value, this says coaching is worth almost 12 extra marks, a huge effect. But the comparison mixes two different populations of students. Now redo it stratum by stratum, comparing coached and non-coached students only within the same ability level.

  • High-ability only: coached mean = 570 / 6 = 95, non-coached mean = 184 / 2 = 92, so the within-stratum effect is 95 minus 92 = 3 marks
  • Medium-ability only: coached mean = 154 / 2 = 77, non-coached mean = 447 / 6 = 74.5, so the within-stratum effect is 77 minus 74.5 = 2.5 marks

Both strata happen to contain eight students each, so the adjusted estimate is simply the average of the two within-stratum effects: (3 + 2.5) / 2 = 2.75 marks.

The gap is dramatic. The naive comparison claimed an 11.625-mark advantage for coaching. Once prior ability is held fixed, the estimated effect drops to 2.75 marks. Coaching still appears to help a little, since students who took it scored, on average, about 2.75 marks higher than similar-ability students who did not, but roughly three-quarters of the originally observed gap was really explained by who chooses to take coaching in the first place, not by what coaching does to them once they are there.

Here is the same computation written as Python, which becomes essential once a dataset grows too large to average by hand:

students = [
    {"ability": "high", "coaching": 1, "score": 95},
    {"ability": "high", "coaching": 1, "score": 96},
    {"ability": "high", "coaching": 1, "score": 94},
    {"ability": "high", "coaching": 1, "score": 95},
    {"ability": "high", "coaching": 1, "score": 96},
    {"ability": "high", "coaching": 1, "score": 94},
    {"ability": "high", "coaching": 0, "score": 93},
    {"ability": "high", "coaching": 0, "score": 91},
    {"ability": "medium", "coaching": 1, "score": 78},
    {"ability": "medium", "coaching": 1, "score": 76},
    {"ability": "medium", "coaching": 0, "score": 74},
    {"ability": "medium", "coaching": 0, "score": 75},
    {"ability": "medium", "coaching": 0, "score": 73},
    {"ability": "medium", "coaching": 0, "score": 76},
    {"ability": "medium", "coaching": 0, "score": 74},
    {"ability": "medium", "coaching": 0, "score": 75},
]

def mean(values):
    return sum(values) / len(values)

# Naive comparison: ignore ability completely
coached = [s["score"] for s in students if s["coaching"] == 1]
not_coached = [s["score"] for s in students if s["coaching"] == 0]
naive_effect = mean(coached) - mean(not_coached)
print("Naive effect (ignoring ability):", naive_effect)

# Adjusted comparison: compare within each ability stratum, then average
stratum_effects = []
for level in ["high", "medium"]:
    in_level_coached = [s["score"] for s in students
                         if s["ability"] == level and s["coaching"] == 1]
    in_level_not = [s["score"] for s in students
                     if s["ability"] == level and s["coaching"] == 0]
    effect = mean(in_level_coached) - mean(in_level_not)
    stratum_effects.append(effect)
    print(f"{level}-ability stratum effect:", effect)

adjusted_effect = mean(stratum_effects)
print("Adjusted effect (controlling for ability):", adjusted_effect)

Running this prints a naive effect of 11.625, a high-ability stratum effect of 3.0, a medium-ability stratum effect of 2.5, and an adjusted effect of 2.75, matching the by-hand arithmetic exactly. That match is not a coincidence: stratification is simply "group, then average," carried out carefully enough to keep the confounder from leaking back into the comparison.

This stratified estimate is only as good as the confounders it accounts for. If some other factor, say family income, which could affect both access to coaching and access to other resources like a quiet study room or a private tutor at home, was also unevenly spread across the groups and never included in the stratification, some bias could still remain. Adjustment can only remove the influence of confounders that were actually measured and controlled for.

When the Story Can Flip Entirely: Simpson's Paradox

Confounding does not always just inflate or shrink an effect the way it did in the coaching example. Occasionally, adjusting for a confounder reverses the direction of the result completely, a phenomenon known as Simpson's Paradox. The most famous real example comes from a study of 1973 graduate admissions data at the University of California, Berkeley. Looking at the university as a whole, men were admitted at a noticeably higher rate than women, a gap large enough to suggest bias. But when researchers broke the numbers down department by department, the great majority of individual departments showed no bias against women, and several even favoured women slightly. The reversal happened because women had disproportionately applied to the university's most competitive departments, which had low admission rates for every applicant, while men had applied more often to less competitive ones. Department choice was the confounder, and once it was accounted for, the picture changed almost entirely.

Simpson's Paradox is a warning that stratifying on the wrong variable, or failing to stratify on the right one, can point an analysis toward exactly the wrong conclusion, not merely a slightly inflated one. This is why causal inference practitioners increasingly sketch simple causal diagrams, maps of which variables are believed to influence which others, before running any calculation. For the coaching example, the diagram would read:

  • Ability → Coaching (more able or more ambitious students are more likely to join coaching)
  • Ability → Score (more able students tend to score higher regardless of coaching)
  • Coaching → Score (coaching may also genuinely raise scores on its own)

Drawing this out makes it visible that Ability sits upstream of both Coaching and Score, the textbook signature of a confounder, and that it must be held fixed, whether by stratifying or by more advanced techniques such as regression adjustment, matching, or instrumental variables, before Coaching → Score can be read off cleanly.

Causal Thinking in AI and Machine Learning

Correlation-versus-causation is not just a statistics-class exercise; it sits underneath some of the best-known failures in machine learning. In a widely cited 2016 experiment, researchers at the University of Washington deliberately built an image classifier to distinguish photographs of wolves from huskies, then used an interpretability technique to check what the model was actually paying attention to. It turned out the model had barely learned anything about the animals themselves. Because most of the wolf photographs in its training data happened to have snow in the background, the classifier had learned to detect snow, a confounder, and was using "is there snow in this picture" as a stand-in for "is this a wolf." Shown a fresh photo of a husky standing in snow, it confidently, and wrongly, predicted wolf.

A machine learning model trained on historical or observational data has no built-in way to distinguish a genuine cause from a confounding shortcut. It simply learns whatever pattern most reliably predicts the label in its training set, and background snow predicted "wolf" just as reliably as fur patterns did, sometimes more so. This is the same failure as Radhika's cousin crediting UPI for a Diwali sales bump, or a hurried analyst crediting coaching classes with an 11.625-mark gain that mostly belonged to prior ability. The scale is different, a neural network with millions of parameters instead of sixteen students in a spreadsheet, but the discipline needed to avoid the mistake is identical: ask what else could explain this pattern before believing that the thing you wanted to be the cause actually is one. This is also why causal machine learning, building models explicitly designed to estimate the effect of an intervention rather than just predict an outcome, has become an active area of research, applied to problems ranging from choosing which customers to target with a discount to estimating the effect of a public health policy from observational records.

Back to Radhika's Counter

So did UPI cause Radhika's sales to rise? The honest answer, using everything in this chapter, is: possibly a little, but the raw before-and-after comparison her cousin made cannot tell us that on its own. To find out properly, she would need something closer to a controlled comparison, perhaps checking a few nearby shops that stayed cash-only through the same festive season, to see whether their sales rose by a similar percentage without ever touching UPI. If the cash-only shops rose almost as much, the festive season was doing most of the work. If Radhika's shop rose noticeably more than theirs, that gap is a far more credible estimate of what UPI itself contributed.

That habit, instinctively asking "compared to what?" and "what else changed at the same time?" before accepting that one thing caused another, is the practical takeaway of this chapter. Every time a headline, an advertisement, or a dashboard claims that A caused B based on numbers that simply moved together, the same questions apply. Is there a plausible confounder driving both variables at once? Has anyone compared this to a genuine counterfactual, ideally through randomization? And if adjustment was used instead of randomization, were all the important confounders actually measured? Learning to ask those questions, and now knowing how to test them with a stratified comparison or a few lines of Python, is what separates reading a correlation from understanding a cause.

Key Takeaways — Summary and Recap

Let us recap what we covered: the core ideas behind introduction to causal inference, how they connect to real-world applications, and why they matter for your journey in computer science. Remember these key points as you move forward. For competitive exam preparation (CBSE, JEE, BITSAT), focus on understanding the WHY behind each concept, not just the WHAT.

← Gaussian Mixture Models and Soft ClusteringAutomatic Differentiation and Computational Graphs →

Found this useful? Share it!

📱 WhatsApp 🐦 Twitter 💼 LinkedIn