7  Random variables

Author

Karl Gregory

Recall from Definition 1.1 that a statistical experiment (experiment for short) is a process which generates an outcome such that i) more than one outcome is possible, ii) the set of possible outcomes is known, and iii) it is not known in advance what the outcome will be.

Recall that we denoted by \(S\) the sample space of an experiment, which is the set of possible outcomes. The sample space \(S\) may consist of numbers; on the other hand, it could consist of outcomes which are not numbers, for example in the experiment of flipping a coin, for which we could write the sample space as \(S = \{\text{heads},\text{tails}\}\).

A random variable is a numerical representation of the outcome of a statistical experiment. More precisely, it is a function taking outcomes in the sample space and returning values on the real number line. We will denote random variables by capital letters, typically \(X,Y\), or \(Z\) (or \(W\) or \(T\), but really any letter we want to use). In the experiment of flipping a coin, we might define the random variable \(X\) as the function \[ X = \left\{\begin{array}{ll} 0& \text{ if the outcome is tails}\\ 1& \text{ if the outcome is heads} \end{array}\right. \] In an experiment with a sample space already consisting of numbers, a random variable can be defined to simply return the numerical outcome of the experiment directly. For example, in the experiment of spinning a top and recording how long it spins, we had \(S = [0,\infty)\), and we may define a random variable corresponding to this experiment by defining \(X\) as the function which merely returns the numeric outcome.

Along the same lines as a statistical experiment, we can think of a random variables a yet-to-be-observed number for which i) more than one value is possible, ii) the set of possible values is known, and iii) it is not known in advance what the value will be.

So random variables turn outcomes into numeric values.

Just as we defined for a statistical experiment the sample space \(S\) as the set of all possible outcomes, we define for a random variable what we call the support, which is the set of all possible values it can take on. Formally:

Definition 7.1 (Random variable) Given a statistical experiment with sample space \(S\), a random variable \(X\) is a function taking outcomes in \(S\) and returning values on the real number line \(\mathbb{R}\). The set of all possible values \(X\) can take is called the support of \(X\) and is denoted by \(\mathcal{X}\).

If we use \(Y\) to denote a random variable, we will use \(\mathcal{Y}\) to denote its support.

Example 7.1 (Flipping two coins) The experiment of flipping two coins has sample space \(S = \{HH,HT,TH,TT\}\). We can define \(X\) as the number of heads and \(Y\) as the number of tails. Then \(X\) and \(Y\) have support sets \(\mathcal{X}= \{0,1,2\}\) and \(\mathcal{Y}= \{0,1,2\}\), respectively.

Example 7.2 (Rolling two dice) The experiment of rolling two dice has sample space given in Example 1.5. If we define \(X\) to be the sum of the rolls and \(Y\) to be the absolute values of the difference between the rolls, we find \(\mathcal{X}= \{2,\dots,12\}\) and \(\mathcal{Y}= \{0,\dots,5\}\).

Example 7.3 (Spinning a top) The experiment of spinning a top and recording how long it spins has sample space \(S = [0,\infty)\). Here we could define a random variable \(X\) as simply equaling the outcome of the experiment, so it would have support \(\mathcal{X}= [0,\infty)\). We could define \(Y\) as the spinning time of the top rounded to the nearest second, so it would have support \(\mathcal{Y}= \{0,1,2,\dots\}\).

A key feature of a random variable \(X\) is that its value cannot be predicted with certainty. Hence its name. Just as we previously considered assigning probabilities to events \(A\) or \(B\) and so on (where these were subsets of the sample space), we will now consider assigning probabilities to events concerning random variables, say \(X\) or \(Y\).

In particular, we will consider how to compute probabilities of the form \[ P(X \in A) \] where \(A\) is a subset of the real numbers \(\mathbb{R}\) and “\(\in\)” means “in” or “belongs to”. We would read \(P(X \in A)\) as “the probability that \(X\) takes one of the values in the set \(A\)”.

Example 7.4 (Rolling a die) Roll a die and define \(X\) as the number rolled. Then we have \(\mathcal{X}= \{1,\dots,6\}\) and we can write \(P(X \in \{1,2\}) = 1/3\) or \(P(X \in \{5\}) = 1/6\). We can also write \(P( 1 < X \leq 4) = 1/2\) or \(P(X = 1) = 1/6\). All of these are examples of probabilities of the form \(P(X \in A)\), where \(A \subset \mathbb{R}\) (\(A\) is a subset of the real numbers).

In order to obtain such probabilities in general, we will need to have in hand what is called the probability distribution of the random variable. The probability distribution tells us what values a random variable can take and assigns probabilities to these values. Before introducing probability distributions, it will be important to distinguish between two types of random variables.

Definition 7.2 (Two types of random variables) A random variable is a discrete random variable if we can list or begin to list the values in the support. There may be a finite number of values or an infinite number.1 A random variable is a continuous random variable if its support is an interval of the form \([a,b]\), \([a,b)\), \((a,b]\), or \((a,b)\) or a union of such intervals, where \(a\) and \(b\) are real numbers or equal to \(\infty\) or \(-\infty\).

We will consider these two types of random variables in turn, starting with discrete random variables, for which probability distributions are easier to conceptualize and write down.


  1. Using more precise mathematical language, we would say a random variable is discrete if its support is countable, where this means essentially that we can list the values or at least begin to list them.↩︎