liveBook · Manning

Random variable

As explained in Causal AI

A random variable is a variable whose possible values and uncertainty are described by a probability distribution.

A random variable represents the uncertain outcome of a phenomenon. Its possible values may be discrete or continuous. For a three-sided die, write X for the roll and X=2 for the event that the observed outcome is 2; lowercase x stands for any possible outcome. A recorded roll is one outcome, not the random variable itself. section 2.1.1 section 2.3

A probability distribution assigns probability values to possible outcomes. For a discrete X, P(X=x) is the probability of one outcome, while P(X) denotes the distribution across all outcomes. Each probability is between zero and one, and the probabilities sum to one. Continuous variables use probability densities instead; those densities integrate to one. section 2.1.1 section 2.1.2

Listing 2.1 Implementing a discrete distribution table in pgmpy
from pgmpy.factors.discrete import DiscreteFactor
dist = DiscreteFactor(
    variables=["X"],    #1
    cardinality=[3],    #2
    values=[.45, .30, .25],  #3
    state_names= {'X': ['1', '2', '3']}     #4
)
print(dist)

A pgmpy DiscreteFactor specifies one variable, its three possible states, and their probabilities: 0.45, 0.30, and 0.25. section 2.1.2

From outcomes to an expectation

If X takes values 1, 2, and 3 with probabilities 0.45, 0.30, and 0.25, its expected value is E(X)=1(0.45)+2(0.30)+3(0.25)=1.8. This is a probability-weighted average, not a fourth possible die outcome. section 2.1.2 section 2.1.10

With multiple random variables, relationships matter as much as individual distributions. Independence means observing X does not change the probabilities for Y; conditional independence means this holds after accounting for another variable. Such constraints simplify joint distributions. In a causal model, variables can represent causes and effects, while parameters characterize their distributions. An ideal intervention fixes its target variable and changes distributions of causally downstream variables. section 2.1.9 section 7.3 section 2.1.6

How Causal AI covers it

How deep it goes
Defines discrete outcomes and probability values, then extends to expectations and dependence; mentions continuous densities without working through integration.
Examples
Uses die rolls and coin flips for outcomes, plus a three-state probability table implemented with pgmpy.
What it assumes
Builds notation from dice and coin outcomes, favoring discrete arithmetic over integral calculus.
What you can do after
Apply it via pgmpy DiscreteFactor to represent a finite-outcome distribution and calculate a probability-weighted expectation.
How it connects
Connects probability distributions and expected values to conditional independence, data-generating processes, and causal interventions.

Also explained in

Compare how 5 books explain random variable →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.