Unit 4, lesson 28

Functions of Discrete Random Variables

How to find the distribution of a function of a discrete random variable by adding the masses in each preimage, for one-to-one maps, many-to-one maps and the positive part.

  • Video 28
  • Random Variables and Their Distributions

A score change can be negative or positive, but often the quantity of interest is its size, its square, or only the gains. Each of these is a new random variable, and its probabilities have to come from the distribution of the original one. The difficulty is that several inputs can produce the same output, so the probability that the square equals 11 can collect the masses of both −1-1 and 11. This lesson gives one rule that works for every discrete random variable, namely adding the masses of all inputs that land on a given output, and applies it to one-to-one maps, many-to-one maps and the positive part.

Key terms

Function of a random variable

Definition Let XX be a discrete random variable on a sample space Ω\Omega with support SS, the set of values with positive probability, and let gg be a real-valued function defined at every value that XX can take. The random variable Y=g(X)Y = g(X) assigns to each outcome ω\omega the number g(X(ω))g(X(\omega)). It is again discrete, and its support is the set of outputs of support points,

g(S)={g(x):x∈S}.g(S) = \{ g(x) : x \in S \}.

In plain words Apply the rule to the number that XX produces. No new randomness enters, because the value of XX fixes the value of YY, so every probability about YY is inherited from XX.

Example In the key terms on this page, XX is a constructed score change with the following distribution.

xx−2-2−1-1001122
pX(x)p_X(x)0.100.100.200.200.300.300.250.250.150.15

The square Y=X2Y = X^2 sends −2,−1,0,1,2-2, -1, 0, 1, 2 to 4,1,0,1,44, 1, 0, 1, 4. Its support is the set {0,1,4}\{0, 1, 4\} with three values, not a list of five outputs with repeats. A constant function such as g(x)=5g(x) = 5 is allowed too. It gives a random variable that equals 55 with probability 11.

Preimage

Definition For a function gg and a set BB of real numbers, the preimage of BB under gg is the set of inputs whose output lies in BB,

g−1(B)={x:g(x)∈B}.g^{-1}(B) = \{ x : g(x) \in B \}.

For a single value yy it is g−1({y})={x:g(x)=y}g^{-1}(\{y\}) = \{ x : g(x) = y \}. The notation does not require gg to have an inverse function, and a preimage may contain several points or none. The events {Y∈B}\{Y \in B\} and {X∈g−1(B)}\{X \in g^{-1}(B)\} are the same event, so

P(Y∈B)=P(X∈g−1(B)).P(Y \in B) = P\bigl(X \in g^{-1}(B)\bigr).

In plain words To find the probability of a statement about YY, turn it into a statement about XX by asking which inputs make it true. Only inputs in the support of XX carry probability, so solutions of g(x)=yg(x) = y outside the support contribute 00.

Example For Y=X2Y = X^2 the preimage of {1}\{1\} is {−1,1}\{-1, 1\} and the preimage of {4}\{4\} is {−2,2}\{-2, 2\}. The event Y>1Y > 1 happens exactly when X2>1X^2 > 1, and the support points with that property are −2-2 and 22, so P(Y>1)=0.10+0.15=0.25P(Y > 1) = 0.10 + 0.15 = 0.25. The preimage of {9}\{9\} is {−3,3}\{-3, 3\}, which contains no support point of XX, so P(Y=9)=0P(Y = 9) = 0.

Collecting probability mass

Definition Let Y=g(X)Y = g(X), where XX is discrete with support SS and PMF pXp_X. For every real number yy,

pY(y)=∑x∈Sg(x)=ypX(x),p_Y(y) = \sum_{\substack{x \in S \\ g(x) = y}} p_X(x),

the total mass of the support points in the preimage of {y}\{y\}. An empty sum equals 00. Each support point of XX contributes its mass to exactly one output, so the masses of YY are nonnegative and add to 11. When a preimage contains infinitely many support points, its sum is a series of nonnegative terms, and its value does not depend on the order of the terms.

In plain words Draw an arrow from each input to its output and carry the input’s probability along the arrow. Where several arrows meet, add what they carry. A transformation can merge probability but cannot create or destroy any, so a total different from 11 signals a mistake, such as a row that was missed or counted twice.

Example For Y=X2Y = X^2 the output 00 collects the input 00, the output 11 collects −1-1 and 11, and the output 44 collects −2-2 and 22. So

pY(0)=0.30,pY(1)=0.20+0.25=0.45,pY(4)=0.10+0.15=0.25,\begin{aligned} p_Y(0) &= 0.30, \\[0.4em] p_Y(1) &= 0.20 + 0.25 = 0.45, \\[0.4em] p_Y(4) &= 0.10 + 0.15 = 0.25, \end{aligned}

and the masses total 0.30+0.45+0.25=10.30 + 0.45 + 0.25 = 1.

One-to-one map

Definition A function gg is one-to-one on the support SS of XX if distinct points of SS always have distinct outputs, that is, if g(x1)=g(x2)g(x_1) = g(x_2) with x1x_1 and x2x_2 in SS forces x1=x2x_1 = x_2. Then every preimage contains at most one support point, nothing is merged, and Y=g(X)Y = g(X) has pY(g(x))=pX(x)p_Y(g(x)) = p_X(x) for every xx in SS. Whether a map is one-to-one on SS depends on the support as well as on the formula.

In plain words The values move, but each mass travels with its own value. Write the new support explicitly, and when you sort it, move every probability together with its value.

Example The map Z=3X+1Z = 3X + 1 sends −2,−1,0,1,2-2, -1, 0, 1, 2 to −5,−2,1,4,7-5, -2, 1, 4, 7, so ZZ takes these values with the unchanged masses 0.10,0.20,0.30,0.25,0.150.10, 0.20, 0.30, 0.25, 0.15. The decreasing map W=−XW = -X reverses the order. Sorted from smallest to largest, WW takes −2,−1,0,1,2-2, -1, 0, 1, 2 with masses 0.15,0.25,0.30,0.20,0.100.15, 0.25, 0.30, 0.20, 0.10, and keeping the old probability column beside the sorted values would describe a different distribution. Squaring is not one-to-one on the support of this XX, but it is one-to-one on {0,1,2}\{0, 1, 2\}, and in general it merges no mass when every support value is nonnegative.

Many-to-one map

Definition A function gg is many-to-one on the support SS of XX if at least two distinct points of SS have the same output. Then some preimage contains two or more support points, and their masses are added to give a single mass of Y=g(X)Y = g(X). On the event that YY takes such an output, the value of YY does not determine the value of XX.

In plain words Several inputs land on one output, so their probabilities pile up there. Solving g(x)=yg(x) = y for one convenient root, as if gg had an inverse, misses the other inputs.

Example Taking only the positive square root of 11 keeps the input 11 alone and reports 0.250.25 for P(X2=1)P(X^2 = 1), which misses the input −1-1. The correct value is 0.20+0.25=0.450.20 + 0.25 = 0.45. The absolute value ∣X∣\lvert X \rvert takes 0,1,20, 1, 2 with masses 0.30,0.45,0.250.30, 0.45, 0.25. That is the same list of masses as for X2X^2, but on different values, so the two variables have different distributions. The indicator BB that equals 11 when X≥1X \ge 1 and 00 otherwise has P(B=1)=0.25+0.15=0.40P(B = 1) = 0.25 + 0.15 = 0.40 and P(B=0)=0.60P(B = 0) = 0.60. Knowing that B=1B = 1 says only that XX was 11 or 22.

Positive part

Definition The positive part of a real number xx is x+=max⁡(x,0)x^{+} = \max(x, 0), and the positive part of a random variable XX is X+=max⁡(X,0)X^{+} = \max(X, 0). It keeps nonnegative values and replaces negative values by 00. For discrete XX,

P(X+=0)=P(X≤0),P(X^{+} = 0) = P(X \le 0),

and P(X+=x)=pX(x)P(X^{+} = x) = p_X(x) for every x>0x > 0. The negative part is X−=max⁡(−X,0)X^{-} = \max(-X, 0), and every value satisfies X=X+−X−X = X^{+} - X^{-} and ∣X∣=X++X−\lvert X \rvert = X^{+} + X^{-}.

In plain words Gains are kept and losses are recorded as zero. Every input at or below 00 goes to 00, so the mass at 00 collects the old zero together with all the negative values.

Example For the score change, the positive part R=X+R = X^{+} sends −2-2, −1-1 and 00 to 00. Its mass at zero is 0.10+0.20+0.30=0.600.10 + 0.20 + 0.30 = 0.60, and the other masses are P(R=1)=0.25P(R = 1) = 0.25 and P(R=2)=0.15P(R = 2) = 0.15, for a total of 11. Putting only the old zero row’s mass at zero would leave 0.300.30 there, and the masses would add to only 0.700.70.

Check yourself

  1. For the score change XX on this page, find the PMF of the capped square V=min⁡(X2,1)V = \min(X^2, 1) and check that its masses add to 11.
Show the answer

The inputs −2,−1,0,1,2-2, -1, 0, 1, 2 have outputs 1,1,0,1,11, 1, 0, 1, 1. Only the input 00 gives the output 00, so P(V=0)=0.30P(V = 0) = 0.30. The other four inputs all give 11, so P(V=1)=0.10+0.20+0.25+0.15=0.70P(V = 1) = 0.10 + 0.20 + 0.25 + 0.15 = 0.70. The masses add to 0.30+0.70=10.30 + 0.70 = 1. The cap merges −2-2 and 22 with −1-1 and 11, even though their squares are different.

  1. Let XX take the values −1,0,2,3-1, 0, 2, 3 with probabilities 14,14,13,16\tfrac14, \tfrac14, \tfrac13, \tfrac16. Find the PMF of Y=min⁡(X2,4)Y = \min(X^2, 4) and the PMF of the positive part X+X^{+}.
Show the answer

The outputs of YY are 1,0,4,41, 0, 4, 4. So P(Y=0)=14P(Y = 0) = \tfrac14, P(Y=1)=14P(Y = 1) = \tfrac14 and P(Y=4)=13+16=12P(Y = 4) = \tfrac13 + \tfrac16 = \tfrac12. The cap merges the inputs 22 and 33, whose squares 44 and 99 differ.

For the positive part, the inputs −1-1 and 00 both go to 00, so P(X+=0)=14+14=12P(X^{+} = 0) = \tfrac14 + \tfrac14 = \tfrac12, while P(X+=2)=13P(X^{+} = 2) = \tfrac13 and P(X+=3)=16P(X^{+} = 3) = \tfrac16. Both lists of masses add to 11.

  1. Let XX take the values 0,1,2,30, 1, 2, 3 with probabilities 0.1,0.2,0.3,0.40.1, 0.2, 0.3, 0.4. Is g(x)=x2g(x) = x^2 one-to-one on the support? Is h(x)=(x−1)2h(x) = (x - 1)^2? Find the PMF of h(X)h(X).
Show the answer

The squares of 0,1,2,30, 1, 2, 3 are 0,1,4,90, 1, 4, 9, all distinct, so gg is one-to-one on this support. The variable X2X^2 takes these four values with the unchanged masses 0.1,0.2,0.3,0.40.1, 0.2, 0.3, 0.4.

The map hh sends 0,1,2,30, 1, 2, 3 to 1,0,1,41, 0, 1, 4. The inputs 00 and 22 share the output 11, so hh is many-to-one on the support. Collecting masses gives P(h(X)=0)=0.2P(h(X) = 0) = 0.2, P(h(X)=1)=0.1+0.3=0.4P(h(X) = 1) = 0.1 + 0.3 = 0.4 and P(h(X)=4)=0.4P(h(X) = 4) = 0.4, which add to 11. The same formula x2x^2 that merges −1-1 and 11 on the score change merges nothing here, because whether a map is one-to-one depends on the support.

How this lesson connects