Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Random variables

Introduction

The foundations of probability are built on sets, yet data is more naturally stored and more easily computed on if it is represented numerically.

Random variables match each outcome in our sample space to a value on the number line.

In addition to computational advantages, random variables help us extract from our data the most important characteristics, and they serve as building blocks which we can use to create powerful models. Random variables are also a language we can use to communicate our modeling efforts to other mathematicians, statisticians, and data scientists.

Suppose we hypothesize that the frequency of social media posts on some popular outlet are related to influenza-like illness (ILI)---a syndromic diagnosis suggesting a patient may have influenza. A patient is diagnosed with ILI if their temperature is measured to be at or above 38C and symptoms resembling the flu. Because influenza is most active in winter and spring, we collect a random sample, each day, of social media posts from September to May and in addition we collect the proportion of patients who are admitted to the hospital and are diagnosed with influenza-like illness at the US national level.

The above hypothesis, data collection, and future inference has numerous details. However, we will see shortly that we can simplify our hypothesis by using random variables.

Maps from the sample space to the number line

Given a sample space G\mathcal{G}, a random variable, (e.g. XX), is a function from each element in G\mathcal{G}---from each outcome---to a value on the real number line. The real number line contains all numbers: integer and decimal, from negative to positive infinity.

Example: Suppose our sample space contains two elements G={a,b}\mathcal{G} = \{ a,b \}. We may decide to define a random variable XX that maps the outcome aa to the value -1 and the outcome bb to the value 1. In otherwords, X(a)=−1X(a)=-1 and X(b)=1X(b)=1. We could as well define a random variable YY on the same sample space such that Y(a)=0Y(a)=0 and Y(b)=1Y(b)=1.

Example: Suppose our sample space contains all integers from 0 to 1000 G={0,1,2,3⋯ ,1000}\mathcal{G} = \{0,1,2,3\cdots,1000 \}. We may be most interested in when an integer is even or odd, and so we can define a random variable Y(y)=0Y(y)=0 when yy, our outcome, is an odd integer and Y(y)=1Y(y)=1 when yy is even. This is an example of how a random variable can distill down a sample space with many outcomes into a random variable with two.

Example: Suppose we decide to study the relationship between the cumulative total number of cigarettes smoked by a person form the date that they started smoking and the presence of lung cancer. We define our sample space to be G={(x,y)∣x∈Z,y∈{0,1}}\mathcal{G} = \{ (x,y) | x \in \mathbb{Z}, y \in \{0,1\} \}. We define two random variables, a random variable XX that maps the outcome (x,y)(x,y) to the value in the first position xx, and a random variable YY that maps the outcome(x,y)outcome (x,y) to the value in the second position yy. Though our outcomes are linked, we can use random variables to think about two separate outcomes---cigarettes smoked and lung cancer---and how they interact.

A new sample space

When we build a random variable (X)(X) that maps outcomes to values on the number line we create a new sample space which we will call the support of XX or supp(X)supp(X). Define a sample space G\mathcal{G} without outcomes oio_{i}. Then the support of X is

supp(X)={x∣X(o)=xforsomeoutcomeoinG}\begin{aligned} supp(X) = \{x | X(o) = x for some outcome o in \mathcal{G} \} \end{aligned}

Our new sample space is the set of all the potential values that our random variable XX can produce. This is a sample space linked to G\mathcal{G}, but in practice after we develop a random variable we often no longer reference G\mathcal{G}.

In our above example where G={a,b}\mathcal{G} = \{a,b\}, the random variable XX has support supp(X)={−1,1}supp(X) = \{-1,1\} and supp(Y)={0,1}supp(Y)=\{0,1\}. Lets look at another example, when above G\mathcal{G} is the set of all integers from 0 to 1000. Even though the sample space is quite large, the random variable that maps the integers to 0 when they are odd and 1 when even has a small support (supp(Y)={0,1})(supp(Y) = \{0,1\}).

How to assign probabilities to a random variable

Random variable themselves do not require that we include the probability of each of their values. Random variables are a function from outcomes to the real numbers---nothing more. That said, in practice we build random variables expecting that the probabilities we assign to outcomes in our sample space will correspond to probabilities assigned to values of our random variable.

We assign a probability to the value xx, which belongs in the support of random variable XX, the sum of the probabilities of all the outcomes that XX maps to xx.

P(X=x)=P(o1)+P(o2)+⋯+P(on)P(X=x) = P(o_{1}) + P(o_{2}) + \cdots + P(o_{n})

where each outcome o1,o2,⋯ ,ono_{1},o_{2},\cdots,o_{n} is mapped by XX to the value xx. In other words, X(o)=xX(o)=x for each of o1,o2,⋯ ,ono_{1},o_{2},\cdots,o_{n}.

Define a Ω={a,b,c,d,e}\Omega = \{a,b,c,d,e\} and a random variable XX that maps the outcomes to the following values

Outcome P(outcome) X(outcome)


  a         0.1           0
  b         0.25          1
  c         0.15          1
  d         0.3           2
  e         0.2           0

We assign the probability that X=0X=0 as the sum of the probabilities assigned to outcome aa and outcome ee, or

P(X=0)=P({a})+P({e})=0.1+0.2=0.3\begin{aligned} P(X=0) &= P(\{a\}) + P(\{e\})\\ &= 0.1+0.2 = 0.3 \end{aligned}

We can run the same procedure for all the elements in the support of XX,

P(X=1)=P({b})+P({c})=0.25+0.15=0.40P(X=2)=P({d})=0.3=0.30,\begin{aligned} P(X=1) &= P(\{b\}) + P(\{c\})\\ &= 0.25+0.15 = 0.40\\ P(X=2) &= P(\{d\}) = 0.3 = 0.30, \end{aligned}

and organize our work in a table

X P(X=x)


0 0.30 1 0.40 2 0.30

A probability distribution for a random variable XX is a set of tuples where the first position in each tuple is a value in the support of XX and the second position in the tuple is the corresponding probability assigned to that value.

A probability distribution for the random variable XX above is {(0,0.30),(1,0.40),(2,0.30)}\{(0,0.30),(1,0.40),(2,0.30)\}.

Imagine we run an experiment that collects data on marathon runners. We decide to collect the number of elapsed minutes until they finish the race. Our sample space is defined as all positive integers Ω={1,2,3,⋯ ,}\Omega = \{1,2,3,\cdots,\}. We may decide to build a random variable XX that maps outcomes less than 60 to the value 1, outcomes from 61 to 120 to the value 2, and outcomes greater than 120 to the value 3. One potential probability distribution for XX is {(1,0.10),(2,0.50),(3,0.40)}\{(1,0.10),(2,0.50),(3,0.40)\}. For this probability distribution, P(X=1)=0.10P(X=1) = 0.10, P(X=2)=0.50P(X=2) = 0.50, and P(X=3)=0.40P(X=3) = 0.40.

A sample space Ω with elements {a, b, c, d, e} and a random variable X that maps each element in Ω to one the values: 0, 1, or 2. Probabilities corresponding to outcomes in the sample space and how they map to probabilities for each value of X are shown in blue.

![](../figures/chapter2/rvsLink.png)

Probability mass function

There are several supportive tools that we can use to help us better understand random variable we create. The first is the probability mass function, or p.m.f. The probability mass function is a [function]{.underline} that maps values in the support of a random variable XX to their corresponding probabilities. Inputs are values of XX, outputs are probabilities.

The probability mass function is a convenient way to organize a probability distribution and it allows us to transfer all the information we know about functions to random variables.

Define a random variable YY with support {−1,0,1}\{-1,0,1\}, probability distribution {(-1,0.2),(0,0.5),(1,0.3)}, and probability mass function

f(y)={0.2wheny=−10.5wheny=00.3wheny=1f(y) = \begin{cases} 0.2 & when y=-1\\ 0.5 & when y = 0\\ 0.3 & when y=1 \end{cases}

The function---our probability mass function---is a type of function called a piecewise function.

We can ask our pm.f. to return the probability for a given value

f(1)=0.3f(1) = 0.3

and we can visualize our probability mass function using, for example, a barplot.

A barplot for visualizing the probability mass function of our random variable Y. The support of Y is plotted on the horizontal axis and height of each bar corresponds to the probability assigned to that value in the support.[]{#fig.pmfviz label="fig.pmfviz"}{#fig-pmfviz}

Distributed as ff: Because we can use the probability mass function to describe the probability distribution of a random variable, we will often write

Y∼fY \sim f

The above formula is read "the random variable YY is distributed as ff", and what we mean when a random variable is distributed as ff is that the support of YY is the same as the domain of the function ff and that the probability of a value yy is equal to f(y)f(y), or

supp(Y)=dom(f)P(Y=y)=f(y)\begin{aligned} supp(Y) &= dom(f)\\ P(Y = y) &= f(y) \end{aligned}

The probability mass function is a convenient method for assigning probabilities to random variables and visualizing the distribution of a random variable.

Cumulative mass function

The cumulative mass function is a [function]{.underline} that maps values in the support of a random variable XX to the probability that the random variable is less than or equal to this value, or P(X≤x)P(X \leq x).

We use a capital FF to denote a cumulative mass function (c.m.f). The c.m.f. corresponding to random variable XX has a domain equal to the support of XX and produces values between 0 and 1 (the values a function can produce is called the function’s image).

supp(X)=dom(F)image(F)=[0,1]P(X≤x)=F(x)\begin{aligned} supp(X) &= dom(F)\\ image(F) &= [0,1]\\ P(X \leq x) &= F(x) \end{aligned}

The c.m.f. too can be visualized and we could also use the c.m.f. to describe the probability distribution of a random variable. This is because we can use the c.m.f. to derive the p.m.f.

A barplot for visualizing the cumulative mass function of our random variable Y. The support of Y is plotted on the horizontal axis and height of each bar corresponds to the probability assigned to values (v) less than or equal to v in the support.[]{#fig.pmfviz label="fig.pmfviz"}{#fig-pmfviz}

For a random variable

X∼fsupp(X)={0,1,2,3}f(x)={00.110.320.230.4\begin{aligned} X &\sim f\\ supp(X) &= \{0,1,2,3\}\\ f(x) &= \begin{cases} 0 & 0.1\\ 1 & 0.3\\ 2 & 0.2\\ 3 & 0.4\\ \end{cases} \end{aligned}

The c.m.f is then

F(x)={00.110.3+0.1=0.420.2+0.3+0.1=0.630.4+0.2+0.3+0.1=1\begin{aligned} F(x) = \begin{cases} 0 & 0.1\\ 1 & 0.3 + 0.1 = 0.4\\ 2 & 0.2+0.3+0.1 = 0.6\\ 3 & 0.4+0.2+0.3+0.1 = 1\\ \end{cases} \end{aligned}

We can use the c.m.f (F(x))(F(x)) to compute any p.m.f (f(x)f(x)) too by noticing that for a support {x0,x1,x2,x3,⋯ ,xn−1⋯ ,xn}\{x_{0},x_{1},x_{2},x_{3}, \cdots,x_{n-1}\cdots,x_{n}\} where the values in this set are ordered form smallest to largest

f(xi)=[f(xi)+f(xi−1)+⋯f(x0)]−[f(xi−1)+⋯f(x0)]=F(xi)−F(xi−1).\begin{aligned} f(x_{i}) &= \left[f(x_{i}) + f(x_{i-1}) + \cdots f(x_{0}) \right] - \left[f(x_{i-1}) + \cdots f(x_{0})\right] \\ &=F(x_{i}) - F(x_{i-1}). \end{aligned}

Because the p.d.f. and c.m.f equivalently describe the probability distribution of a random variable we can write X∼FX\sim F or X∼fX \sim f.

Two or more random variables

A single random variable is a useful way to describe a sample space and the probabilities assigned to values on the number line corresponding to outcomes.

But more complicated scientific questions often require several random variables and rules for how they interact. We will explore how to generate multiple random variables on the same sample space. Then we will develop an approach to define probabilities for combinations of random variables, a joint probability mass function and joint cumulative mass function.

Suppose we design a sample space Ω\Omega and build two random variables on this space XX and YY. Because XX and YY are random variables we can think of the support of XX and support of YY as two new sample spaces. Lets assume that the outcomes in supp(X)={x1,x2,x3,⋯ ,xN}supp(X) = \{x_{1},x_{2},x_{3},\cdots,x_{N}\} and that the outcomes in supp(Y)={y1,y2,⋯ ,yM}supp(Y) = \{y_{1},y_{2},\cdots,y_{M}\}. Then we can define a new set of outcomes in the space supp(X)×supp(Y)={xi,yj}supp(X) \times supp(Y) = \{x_{i}, y_{j}\} for all combinations of ii from 1 to NN and jj from 1 to MM.

This new space above maps outcomes in Ω\Omega to a tuple (xi,yj)(x_{i},y_{j}) where the outcomes were mapped by XX to the value xix_{i} and by YY to the value yjy_{j}. If we assign the probability of (xi,yj)(x_{i},y_{j}) to be the the sum of the probabilities of all outcomes in Ω\Omega that XX maps to xix_{i} and YY maps to yiy_{i} then we call this a joint probability distribution.

A pharmaceutical company launches a clinical trial to study adverse events from a novel medicine. The trial enrolls patients and randomizes them to receive the novel drug or optimal medical therapy. The trial expects three potential adverse events which we call ae1ae_{1}, ae2ae_{2}, and ae3ae_{3}. We may choose to define a sample space Ω={(nov,ae1),(nov,ae2),(nov,ae3),(omt,ae1),(omt,ae2),(omt,ae3)}\Omega = \{(nov,ae_{1}),(nov,ae_{2}),(nov,ae_{3}),(omt,ae_{1}),(omt,ae_{2}),(omt,ae_{3})\} and further build a random variable XX that maps outcomes to values 0 when an adverse event was experienced by a control patient and 1 when an adverse event was experienced by a novel drug patient, and a random variable YY that maps adverse event 1 to the value 1, adverse event 2 to the value 2, and adverse event 3 to the value 3.

Ω={(nov,ae1),(nov,ae2),(nov,ae3),(omt,ae1),(omt,ae2),(omt,ae3)}\begin{aligned} \Omega = \{(nov,ae_{1}),(nov,ae_{2}),(nov,ae_{3}),(omt,ae_{1}),(omt,ae_{2}),(omt,ae_{3})\} \end{aligned}
   Event        X

(nov,ae1)(nov,ae_{1}) 1 (nov,ae2)(nov,ae_{2}) 1 (nov,ae3)(nov,ae_{3}) 1 (omt,ae1)(omt,ae_{1}) 0 (omt,ae2)(omt,ae_{2}) 0 (omt,ae3)(omt,ae_{3}) 0

   Event        Y

(nov,ae1)(nov,ae_{1}) 1 (nov,ae2)(nov,ae_{2}) 2 (nov,ae3)(nov,ae_{3}) 3 (omt,ae1)(omt,ae_{1}) 1 (omt,ae2)(omt,ae_{2}) 2 (omt,ae3)(omt,ae_{3}) 3

A joint probability distribution would assign probabilities to all possible pairs of values for XX and YY.

X Y prob


1 1 0.1 1 2 0.05 1 3 0.23 0 1 0.05 0 2 0.30 0 3 0.27

We write P(X=x,Y=y)P(X=x, Y=y) to denote the probability assigned to the joint probability that the random variable XX equals the value xx and the random variable YY equals the value yy. With the above example in mind, P(X=0,Y=2)=0.30P(X=0,Y=2) = 0.30 and this probability could be described as the probability an OMT patient experiences adverse event 2.

Joint probability distributions are often visualized as a table with one random variable’s values representing the rows and the second random variable’s values representing the columns

     Y = 1   Y = 2   Y = 3

X=0 0.05 0.30 0.27 X=1 0.10 0.05 0.23

A joint distribution can be used to compute probabilities that the random variable XX equals the value xx for any value of YY---P(X=x)P(X=x) and also the probability that the random variable YY equals the value yy for any value of xx---P(Y=y)P(Y=y). These probabilities are called marginal probabilities.

The marginal probabilities that XX equals 0, or P(X=0)P(X=0), is computed by summing the joint probabilities where X=0X=0. We can use the same procedure to compute the marignal probability that X=1X=1.

P(X=0)=P(X=0,Y=1)+P(X=0,Y=2)+P(X=0,Y=3)=0.05+0.30+0.27=0.62P(X=1)=P(X=1,Y=1)+P(X=1,Y=2)+P(X=1,Y=3)=0.10+0.05+0.23=0.38\begin{aligned} P(X=0) &= P(X=0,Y=1) + P(X=0,Y=2) + P(X=0,Y=3)\\ &= 0.05+0.30+0.27 = 0.62\\ P(X=1) &= P(X=1,Y=1) + P(X=1,Y=2) + P(X=1,Y=3) \\ &= 0.10+0.05+0.23 = 0.38 \\ \end{aligned}

The same procedure can be done for the random variable YY to find marginal probabilities:

P(Y=1)=P(X=0,Y=1)+P(X=1,Y=1)=0.1+0.05=0.15P(Y=2)=P(X=0,Y=2)+P(X=1,Y=2)=0.05+0.30=0.35P(Y=3)=P(X=0,Y=3)+P(X=1,Y=3)=0.23+0.27=0.50\begin{aligned} P(Y=1) &= P(X=0,Y=1) + P(X=1,Y=1)\\ &= 0.1+0.05 = 0.15 \\ P(Y=2) &= P(X=0,Y=2) + P(X=1,Y=2) \\ &= 0.05+0.30 = 0.35 \\ P(Y=3) &= P(X=0,Y=3) + P(X=1,Y=3) \\ &= 0.23+0.27 = 0.50\\ \end{aligned}

Joint distributions need not be restricted to only two random variables. We can build joint distributions of any number of random variables and can compute marginal probabilities in the same way that we do for a joint distribution of two random variables.

The rules, laws, and theorems of probability that we learned in chapter one carry over to random variables. This is because we can consider a new sample space of values that our random variable can take. Suppose we build two random variables XX that maps outcomes to the the values -1,0,1 and YY that maps outcomes to the values 1,2,3. We can define a new sample space Ω={(x,y)∣x∈supp(X)andy∈supp(Y)}\Omega = \{(x,y) | x \in supp(X) and y \in supp(Y) \} With our new sample space, we can now discuss statements like P(X=x∣Y=y)P(X = x | Y = y).

If we continue with our pharmaceutical example, we can build a new sample space Ω={(0,1),(0,2),(0,3),(1,1),(1,2),(1,3)}\Omega = \{(0,1),(0,2),(0,3),(1,1),(1,2),(1,3)\} and compute, for example, P(X=1∣Y=2)=P(X=1,Y=2)P(Y=2)=0.050.35=0.14P(X=1 | Y=2) = \frac{P(X=1,Y=2)}{P(Y=2)} = \frac{0.05}{0.35} = 0.14.

We can define the conditional probability of the value of one random variable given another as

P(A=a∣B=b)=P(A=a,B=b)P(B=b)\begin{aligned} P(A =a | B =b) = \frac{P(A=a,B=b)}{P(B=b)} \end{aligned}

and so define statistical independence between two random variables, AA and BB, as

P(A=a∣B=b)=P(A=a)foralla∈supp(A),b∈supp(B)\begin{aligned} P(A = a | B=b) = P(A = a) for all a \in supp(A),b \in supp(B) \end{aligned}

We can also translate the law of total probability from events to random variables. For a partition [Y=y1]∪[Y=y2]∪[Y=y3]∪⋯∪[Y=yn][Y=y_{1}] \cup [Y=y_{2}] \cup [Y=y_{3}] \cup \cdots \cup [Y=y_{n}] of the event that the random variable X=xX=x,

P(X=x)=P(X=x∣Y=y1)p(y1)+P(X=x∣Y=y2)p(y2)+P(X=x∣Y=y3)p(y3)⋯+P(X=x∣Y=yn)p(yn)\begin{aligned} \begin{aligned} P(X=x) = P(X=x|Y=y_{1})p(y_{1}) + P(X=x|Y=y_{2})p(y_{2})\\ + P(X=x|Y=y_{3})p(y_{3}) \cdots + P(X=x|Y=y_{n})p(y_{n}) \end{aligned} \end{aligned}

By thinking of the values of a random variable as outcomes in a new sample space, we can apply our past intuition and the past mechanics of events, sets to a collection of random variables.

Functions of a random variable

There are times that we may wish to summarize the behavior of a random variable. One common way to describe how probability is distributed among values in the support of a random variable is by computing some function of that random variable.

Multiplying and adding a constant to a random variable

Suppose we have defined a random variable XX and wish to study a new random variable Y=g(X)Y = g(X) that is a function of XX. The values and the probabilities assigned to XX, along with the function gg will determine the values in the support of YY and assigned probabilities to these values.

Translation

Define a random variable XX with p.m.f. fXf_{X} and a new random variable Y=X+cY = X+c where cc is a constant. Then the support for YY, supp(Y)={x+c∣x∈supp(X)}supp(Y) = \{ x+c | x \in supp(X) \} and the p.m.f. of YY, fY(y)f_{Y}(y) is

fY(y)=P(Y=y)=P(X+c=y)=P(X=y−c)=fX(y−c)\begin{aligned} f_{Y}(y) &= P(Y=y) \\ &= P(X+c = y)\\ &= P(X=y-c)\\ &= f_{X}(y-c) \end{aligned}

In otherwords, the probability distribution on YY is P={(y,p)  ∣  y=x+candP(X=x)=p}\mathbb{P} = \{ (y,p) \;|\; y=x+c and P(X=x) = p \}. This type of transformation of the random variable XX to YY is called a translation.

Suppose we define a random variable ZZ such that supp(Z)={0,1,2,3,4,5}supp(Z) = \{0,1,2,3,4,5\} and

fZ(z)={0.10ifz=00.05ifz=10.20ifz=20.12ifz=30.07ifz=40.58ifz=5\begin{aligned} f_{Z}(z) = \begin{cases} 0.10 & if z=0\\ 0.05 & if z=1\\ 0.20 & if z=2\\ 0.12 & if z=3\\ 0.07 & if z=4\\ 0.58 & if z=5 \end{cases} \end{aligned}

We can define a new random variable Y=Z−4Y = Z-4. This random variable will have supp(Y)={−4,−3,−2,−1,0,1}supp(Y) =\{-4,-3,-2,-1,0,1\} and

fY(y)={0.10ify=−40.05ify=−30.20ify=−20.12ify=−10.07ify=00.58ify=1\begin{aligned} f_{Y}(y) = \begin{cases} 0.10 & if y=-4\\ 0.05 & if y=-3\\ 0.20 & if y=-2\\ 0.12 & if y=-1\\ 0.07 & if y=0\\ 0.58 & if y=1 \end{cases} \end{aligned}

Scaling

Define a random variable XX with p.m.f. fXf_{X} and a new random variable Y=c⋅XY = c \cdot X where cc is a constant. Then the support for YY, supp(Y)={c⋅x∣x∈supp(X)}supp(Y) = \{ c \cdot x | x \in supp(X) \} and the p.m.f. of YY, fY(y)f_{Y}(y) is

fY(y)=P(Y=y)=P(cX=y)=P(X=y/c)=fX(y/c)\begin{aligned} f_{Y}(y) &= P(Y=y) \\ &= P(cX = y)\\ &= P(X=y/c)\\ &= f_{X}(y/c) \end{aligned}

When we multiply or divide a random variable by a constant to produce a new random variable this is called scaling.

Suppose we define a random variable ZZ such that supp(Z)={0,1,2,3,4,5}supp(Z) = \{0,1,2,3,4,5\} and

fZ(z)={0.10ifz=00.05ifz=10.20ifz=20.12ifz=30.07ifz=40.58ifz=5\begin{aligned} f_{Z}(z) = \begin{cases} 0.10 & if z=0\\ 0.05 & if z=1\\ 0.20 & if z=2\\ 0.12 & if z=3\\ 0.07 & if z=4\\ 0.58 & if z=5 \end{cases} \end{aligned}

We can define a new random variable Y=4⋅ZY = 4 \cdot Z. This random variable will have supp(Y)={0,4,8,12,16,20}supp(Y) =\{0,4,8,12,16,20\} and

fY(y)={0.10ify=00.05ify=40.20ify=80.12ify=120.07ify=160.58ify=20\begin{aligned} f_{Y}(y) = \begin{cases} 0.10 & if y= 0\\ 0.05 & if y= 4\\ 0.20 & if y= 8\\ 0.12 & if y= 12\\ 0.07 & if y= 16\\ 0.58 & if y= 20 \end{cases} \end{aligned}

General transformation of a discrete random variable

We explored translation and scaling as specific ways to use one random variable to generate another. However, there are many functions we can apply to a random variable XX to create a new random variable YY, and we need a more general method to compute the probability mass function for YY.

Build a random variable XX and define YY to be a new random variable such that Y=g(X)Y = g(X). Then the support for YY is supp(Y)={y∣y=g(x)andx∈supp(X)}supp(Y) = \{y | y = g(x) and x \in supp(X) \}, and

fY(y)=fX(x1)+fX(x2)+⋯fX(xn)\begin{aligned} f_{Y}(y) = f_{X}(x_{1}) + f_{X}(x_{2}) + \cdots f_{X}(x_{n}) \end{aligned}

where x1,x2,⋯xn∈g−1(y)x_{1},x_{2}, \cdots x_{n} \in g^{-1}(y). If YY is a function of XX then the probability that the random variable YY will assign to the value yy is the sum of the probabilities the random variable XX assigns to the set of values x1,x2,⋯ ,xnx_{1},x_{2},\cdots,x_{n} that are mapped to yy by the function gg.

Let XX be the random variable with p.m.f

fX(x)={0.01ifx=−20.05ifx=−10.50ifx=00.34ifx=10.10ifx=2\begin{aligned} f_{X}(x) = \begin{cases} 0.01 & if x=-2 \\ 0.05 & if x =-1\\ 0.50 & if x=0\\ 0.34 & if x=1\\ 0.10 & if x=2 \end{cases} \end{aligned}

and also build a new random variable Y=X2Y = X^{2}. Here the function gg is g(x)=x2g(x) = x^{2}. The support of YY is

supp(Y)={−22,−12,02,12,22}={4,1,0,1,4}={0,1,4}\begin{aligned} supp(Y) & = \{ -2^{2},-1^{2},0^{2},1^{2},2^{2} \}\\ & = \{ 4,1,0,1,4 \}\\ & = \{ 0,1,4 \} \end{aligned}

To compute P(Y=0)P(Y=0) we need to sum up the probabilities of all values in supp(X)supp(X) that gg maps to 0. In our case the only value mapped to 0 is the value 0, and so P(Y=0)=P(X=0)=0.50P(Y=0) = P(X=0) = 0.50. To compute P(Y=1)P(Y=1) we need to sum the probabilities of all values that gg maps to the value 1. In this case two values in XX map to 1, the values -1 and 1, and so P(Y=1)=P(X=−1)+P(X=1)=0.05+0.34=0.39P(Y=1) = P(X=-1) + P(X=1) = 0.05+0.34=0.39. Finally, P(Y=4)=P(X=−2)+P(X=2)=0.11P(Y=4) = P(X=-2) + P(X=2) = 0.11 (why?). The pm.f for YY is

fY(y)={0.50ify=00.39ify=10.11ify=4\begin{aligned} f_{Y}(y) = \begin{cases} 0.50 & if y=0\\ 0.39 & if y=1\\ 0.11 & if y=4\\ \end{cases} \end{aligned}

Expectation

Suppose we build a random variable XX with a corresponding probability mass function fXf_{X}.

The expected value of a random variable XX is computed as

E(X)=P(X=x1)x1+P(X=x2)x2+⋯+P(X=xn)xn=f(x1)x1+f(x2)x2+⋯+f(xn)xn\begin{aligned} \mathbb{E}\left(X \right) &= P(X=x_{1})x_{1} +P(X=x_{2})x_{2} + \cdots + P(X=x_{n})x_{n}\\ &= f(x_{1})x_{1} + f(x_{2})x_{2} + \cdots + f(x_{n})x_{n} \end{aligned}

where x1,x2,⋯ ,xnx_{1},x_{2},\cdots,x_{n} are all values in the supp(X)supp(X).

An intuitive definition of the expected value is that E(X)\mathbb{E}(X) is a weighted average of all values in the support of XX where the weight for xix_{i} is the probability of xix_{i}. The expected value of XX will be close to values in supp(X)supp(X) with high probability.

Build a random variable YY with support supp(Y)={−1,0,1}supp(Y) = \{-1,0,1\} and fY={(−1,0.2),(0,0.5),(1,0.3)}f_{Y} = \{(-1,0.2),(0,0.5),(1,0.3)\}. The expected value of YY is E(Y)=0.2(−1)+0.5(0)+0.3(1)=0.1\mathbb{E}(Y) = 0.2 (-1) + 0.5 (0) + 0.3 (1) = 0.1.

Properties of the expectation

The expectation is a linear function, that is E(aY+b)=aE(Y)+b\mathbb{E}(aY + b) = a\mathbb{E}(Y) + b. We can show this by defining a random variable Z=aY+bZ = aY+b and asking

E(Z)=z1fZ(z1)+z2fZ(z2)+⋯znfZ(zn)=(ay1+b)fZ(z1)+(ay2+b)fZ(z2)+⋯(ayn+b)fZ(zn)=a[y1fZ(z1)+y2fZ(z2)+⋯ynfZ(zn)]+b[fZ(z1)+fZ(z2)+⋯+fZ(zn)]=a[y1fZ(z1)+y2fZ(z2)+⋯ynfZ(zn)]+b(why?)=a(y1fY(y1)+y2fY(y2)+⋯ynfY(yn))+b=aE(Y)+b\begin{aligned} \mathbb{E}(Z) &= z_{1} f_{Z}(z_{1}) + z_{2} f_{Z}(z_{2}) + \cdots z_{n} f_{Z}(z_{n})\\ &= (ay_{1}+b) f_{Z}(z_{1}) + (ay_{2}+b) f_{Z}(z_{2})+ \cdots (ay_{n}+b) f_{Z}(z_{n})\\ & \begin{aligned} &= a \left[ y_{1}f_{Z}(z_{1}) + y_{2}f_{Z}(z_{2}) + \cdots y_{n}f_{Z}(z_{n}) \right] \\ &+ b\left[f_{Z}(z_{1}) + f_{Z}(z_{2}) + \cdots + f_{Z}(z_{n}) \right] \end{aligned} \\ &= a \left[ y_{1}f_{Z}(z_{1}) + y_{2}f_{Z}(z_{2}) + \cdots y_{n}f_{Z}(z_{n}) \right] + b \hspace{2mm} (why?) \\ &= a \left( y_{1}f_{Y}(y_{1}) + y_{2}f_{Y}(y_{2}) + \cdots y_{n}f_{Y}(y_{n}) \right) + b \\ &= a \mathbb{E}(Y) + b \end{aligned}

The step [exp.last]{reference-type=“eqref” reference=“exp.last”} deserves some attention. Values ziz_{i} are equal to ayi+bay_{i} + b, they are mapped from the values yiy_{i} and so the probability that ZZ equals ziz_{i} is equivalent to the probability that YY equals yiy_{i}.

Second moment and variance

Define a random variable YY with supp(Y)−{y1,y2,⋯ ,yn}supp(Y) - \{y_{1},y_{2},\cdots,y_{n}\}, then variance is the following function of YY

V(Y)=[y1−E(Y)]2P(Y=y1)+[y2−E(Y)]2P(Y=y2)+⋯+[yn−E(Y)]2P(Y=yn)\begin{aligned} \begin{aligned} V(Y) = \left[y_{1} - \mathbb{E}(Y) \right]^{2} P(Y=y_{1}) + \left[y_{2} - \mathbb{E}(Y) \right]^{2} P(Y=y_{2}) +\\ \cdots + \left[y_{n} - \mathbb{E}(Y) \right]^{2} P(Y=y_{n}) \end{aligned} \end{aligned}

The variance can be thought of as the squared distance of each value in the support of the random variable YY from the expected value weighted by the probability of each value. In some sense, the variance attempts to measure the squared distance from the expected value.

Define a random variable ZZ with probability mass function

fZ(z)={0.14ifz=00.39ifz=10.21ifz=20.26ifz=4\begin{aligned} f_{Z}(z) = \begin{cases} 0.14 & if z=0\\ 0.39 & if z=1\\ 0.21 & if z=2\\ 0.26 & if z=4\\ \end{cases} \end{aligned}

To compute V(Z)V(Z) we need to first compute the expected value of ZZ or E(Z)\mathbb{E}(Z):

E(Z)=fZ(0)⋅0+fZ(1)⋅1+fZ(2)⋅2+fZ(4)⋅4=0.14⋅0+0.39⋅1+0.21⋅2+0.26⋅4=1.85\begin{aligned} \mathbb{E}(Z) &= f_{Z}(0) \cdot 0 + f_{Z}(1) \cdot 1 + f_{Z}(2) \cdot 2 + f_{Z}(4) \cdot 4\\ &= 0.14 \cdot 0 + 0.39 \cdot 1 + 0.21 \cdot 2 + 0.26 \cdot 4\\ &= 1.85 \end{aligned}

Now we can compute the variance

Undefined control sequence: \vspace at position 200: …  \end{aligned}\̲v̲s̲p̲a̲c̲e̲{3mm}\\ 
    &\…

\begin{aligned}
    &\begin{aligned}
        V(Z) = (0-1.85)^{2} \cdot f_{Z}(0) + (1-1.85)^{2} \cdot f_{Z}(1) +\\
          (2-1.85)^{2} \cdot f_{Z}(2) + (4-1.85)^{2} \cdot f_{Z}(4)
    \end{aligned}\vspace{3mm}\\ 
    &\begin{aligned}
        &=(0-1.85)^{2} \cdot 0.14 + (1-1.85)^{2} \cdot 0.39 +\\
        &(2-1.85)^{2} \cdot 0.21 + (4-1.85)^{2} \cdot 0.26
    \end{aligned}  \vspace{3mm}\\ 
    &= 1.97
\end{aligned}

Just in time summation

Summing a sequence of values is performed so frequently in mathematics and statistics that we have developed a special notation that simplifies sums.

Given a sequences of values, x1,x2,x3,⋯ ,xnx_{1}, x_{2}, x_{3}, \cdots, x_{n}, that we wish to sum define the following operator to represent that sum

∑i=1nxi=x1+x2+⋯+xn\begin{aligned} \sum_{i=1}^{n} x_{i} = x_{1} + x_{2} + \cdots + x_{n} \end{aligned}

How the expected value earned its name

Markov inequality

P(X>a)<E(X)aP(X > a) < \frac{ \mathbb{E}(X) }{a}

Suppose we define a random variable XX with a support that takes only non-negative numbers.

E(X)=∑xi∈supp(X)xifX(xi)E(X)=∑xi≤axifX(xi)+∑xi>axifX(xi)E(X)>∑xi>axifX(xi)E(X)>∑xi>aafX(xi)E(X)>a∑xi>afX(xi)E(X)>aP(X>a)E(X)a>P(X>a)\begin{aligned} \mathbb{E}(X) &= \sum_{ x_{i} \in supp(X)} x_{i} f_{X}(x_{i}) \\ \mathbb{E}(X) &= \sum_{ x_{i} \leq a } x_{i} f_{X}(x_{i}) + \sum_{ x_{i} > a } x_{i} f_{X}(x_{i}) \\ \mathbb{E}(X) &> \sum_{ x_{i} > a } x_{i} f_{X}(x_{i}) \\ \mathbb{E}(X) &> \sum_{ x_{i} > a } a f_{X}(x_{i}) \\ \mathbb{E}(X) &> a \sum_{ x_{i} > a } f_{X}(x_{i}) \\ \mathbb{E}(X) &> a P(X > a) \\ \frac{\mathbb{E}(X)}{a} &> P(X > a) \\ \end{aligned}

Chebychev’s inequality

Covariance

Correlation

A Model

Exercises

  1. Suppose Ω={a,b,c}\Omega = \{ a,b,c \} and P({a})=0.2P(\{a\})=0.2, P({b})=0.3P(\{b\})=0.3, P({c})=0.5P(\{c\})=0.5. Define a random variable XX such that X(a)=1X(a)=1, X(b)=1X(b)=1, and X(c)=0X(c)=0. Define a second random variable YY such that Y(a)=0Y(a)=0, Y(b)=1Y(b) = 1, Y(c)=2Y(c)=2.

    1. Compute P(X=1)P(X=1)

    2. Compute P(X=0)P(X=0)

    3. What is supp(X)supp(X) ?

    4. What new sample space does XX generate?

    5. Compute P(Y=1)P(Y=1)

    6. Compute P(Y=0)P(Y=0)

    7. What is supp(Y)supp(Y) ?

    8. What new sample space does YY generate?

  2. Let Ω={1,2,3,4,5,6,7,8,9,10,11}\Omega = \{1,2,3,4,5,6,7,8,9,10,11\}, the set of all positive integers. Further define a random variable KK with the following probability mass function $$\begin{aligned} f(k) = \left( \frac{1}{2} \right) ^{k} & when k \leq 10\ f(11) = 0.009

    \end{aligned}$$

    1. Is the pmf ff a valid probability distribution? Why or why not?

    2. What value of KK is assigned the highest probability?

    3. Please define the cumulative mass function for the random variable KK

  3. Define a random variable with supp(Y)={−3,−2,−1,0,1,2,3}supp(Y) = \{-3,-2,-1,0,1,2,3\} and cumulative mass function $$\begin{aligned} F(y) = \begin{cases} 0.10 & when y = -3\ 0.24 & when y = -2\ 0.36 & when y = -1\ 0.50 & when y = 0\ 0.67 & when y = 1\ 0.78 & when y = 2\ 1.00 & when y = 3\ \end{cases}

    \end{aligned}$$

    1. What is P(Y≤−1)P(Y \leq -1)

    2. What is P(Y=−1)P(Y=-1)

    3. What is P(Y=1)P(Y= 1)

    4. Please define the p.m.f for the random variable YY.

    5. Graph the c.m.f

    6. Graph the p.m.f

  4. Define the following joint distribution of random variable QQ and RR that are mapped from the sample space G\mathcal{G}

    Q R prob


    2 1 0.01 2 2 0.075 2 3 0.13 1 1 0.1 1 2 0.05 1 3 0.17 0 1 0.05 0 2 0.30 0 3 0.115

    1. What is the implied support of QQ?

    2. What is the implied support of RR?

    3. Compute P(Q=1,R=2)

    4. Compute the marginal probabilities for QQ

    5. Compute the marginal probabilities for RR

    6. Compute P(R=1∣Q=0)P(R=1 | Q=0)

    7. The random variable QQ is called statistically independent from RR if for every value q∈supp(Q)q \in supp(Q) and for every value r∈Rr \in R the following is true P(Q=q∣R=r)=P(Q)P(Q=q |R=r) = P(Q). Is QQ statistically independent from RR? Why or why not?

  5. For two events AA and BB that are statistically independent, we found that P(A∩B)=P(A)P(B)P(A \cap B) = P(A)P(B). Please derive an equivalent expression for two random variables by applying the definition of conditional probability and statistical independence to random variables.

  6. Define the following joint distribution of random variable QQ and RR that are mapped from the sample space G\mathcal{G}

    Q R prob


    2 1 0.01 2 2 0.075 2 3 0.13 1 1 0.1 1 2 0.05 1 3 0.17 0 1 0.05 0 2 0.30 0 3 0.115

    1. Please compute E(Q)\mathbb{E}(Q)

    2. Please compute E(R)\mathbb{E}(R)

    3. Please compute V(Q)V(Q)

    4. Please compute V(R)V(R)

  7. Kimberly Palaguachi-Lopez----Class of 2024: Consider the following joint distribution of random variable Z and L that are mapped from the sample space G

    Z L prob


    1 0 0.05 2 0 0.15 3 0 0.19 2 1 0.02 1 1 0.12 3 1 0.04 2 0.5 0.10 3 0.5 0.13 1 0.5 0.20

    1. Please compute the supp(Z)supp(Z)?

    2. Please compute the supp(L)supp(L)?

    3. Solve for P(Z=1,L=1)P(Z=1,L=1)

    4. Solve for the respective marginal probabilities of ZZ

    5. Solve for the respective marginal probabilities of LL

    6. Is the probability distribution for the random variable Z a valid probability distribution? Why or why not? Is the probability distribution for L a valid probability distribution? Why or why not?

  8. Suppose XX is a random variable with support supp(X)={−2,−1,0,1,2,3}supp(X) = \{-2,-1,0,1,2,3\} and Y=∣X∣Y = |X|. Further assume the c.m.f of XX is $$\begin{aligned} F_{X}(x) \begin{cases} 0.05 & if x=-2\ 0.15 & if x=-1\ 0.35 & if x=0\ 0.65 & if x=1\ 0.95 & if x=2\ 1.00 & if x=3 \end{cases}

    \end{aligned}$$

    1. Define the support of YY

    2. Build the p.m.f of YY

    3. Build the c.m.f of YY

  9. Compute ∑i=−5i=5i2/2\sum_{i=-5}^{i=5} i^{2}/2

  10. Simplify the V(X)V(X) into the equation E(X2)−[E(X)]2E(X^{2}) - \left[E(X)\right]^{2}. Hint: Write down the definition of variance using the expectation, then expand the squared terms and simplify.

  11. Define the random variable AA with pmf $$\begin{aligned} f_{B}(b) = \begin{cases} 0.52 & if b=0\ 0.12 & if b=1\ 0.34 & if b=2 \end{cases}

    \end{aligned}$$

    1. Compute E(B)\mathbb{E}(B)

    2. Compute V(B)V(B)

    3. Use Chebychev’s inequality to make a statement about P(B≥b)P(B \geq b)