ContentsChapter 2 · Probability2 of 6

2.2

Random variables

In this chapter
  1. 2.1Conditional probability and Bayes' rule
  2. 2.2Random variables
  3. 2.3Expectation, variance, covariance
  4. 2.4Bernoulli, binomial and Gaussian
  5. 2.5Change of variables
  6. 2.6Entropy and cross-entropy
Before you readA patient’s temperature is measured to infinite precision. What is the probability that it is exactly 37 °C?
Watch: Why “probability of 0” does not mean “impossible” · 3Blue1Brown · Probabilities of probabilities, part 2

A random variable X is a number that depends on chance: a dice roll, a blood pressure, a pixel value. Its distribution says how likely each value is.

A discrete variable has a probability mass function p(x)=P(X=x)p(x) = P(X = x) with ∑xp(x)=1\sum_x p(x) = 1

A continuous variable has a density p(x)≥0p(x) \ge 0 Probability is area under the density:

P(a≤X≤b)=∫abp(x) dx,∫−∞∞p(x) dx=1.P(a \le X \le b) = \int_a^b p(x)\,dx, \qquad \int_{-\infty}^{\infty} p(x)\,dx = 1.

So a density is not a probability. It can be larger than 1, and any single value has probability 0, which answers the question above. The cumulative distribution function is F(x)=P(X≤x)F(x) = P(X \le x)

Two variables have a joint distribution p(x,y)p(x, y) The rules from the last section carry over, with integrals in place of sums for continuous variables:

p(x)=∑yp(x,y),p(y∣x)=p(x,y)p(x).p(x) = \sum_y p(x, y), \qquad p(y \mid x) = \frac{p(x, y)}{p(x)}.

The first is the marginal of X. X and Y are independent when p(x,y)=p(x) p(y)p(x, y) = p(x)\,p(y) for every x and y.

0.511.5-3-2-10123
P(-1 ≤ X ≤ 1) = 0.683p(0) = 0.399
X is normal with mean 0 and spread σ. Probability is the shaded area, not the height. Shrink σ below 0.4 and the peak passes 1, yet the total area stays 1. Set a = b and the probability is 0.
Recall
How do you get a probability from a density p(x)p(x)
Recall
Can a density be larger than 1?
Recall
How do you get the marginal p(x)p(x) from a joint p(x,y)p(x, y)
Exercise
X has density p(x)=c xp(x) = c\,x for 0≤x≤20 \le x \le 2 and 0 elsewhere. Find cc
Exercise
With the same density, find P(X≤1)P(X \le 1)
Exercise
X and Y are each 0 or 1, with P(0,0)=0.1P(0, 0) = 0.1 P(0,1)=0.3P(0, 1) = 0.3 P(1,0)=0.2P(1, 0) = 0.2 and P(1,1)=0.4P(1, 1) = 0.4 where P(x,y)P(x, y) means P(X=x,Y=y)P(X = x, Y = y) Give P(Y=1)P(Y = 1) and then P(X=1∣Y=1)P(X = 1 \mid Y = 1) to three decimal places.