# Random Variables

A random variable, random quantity, aleatory variable or stochastic variable is a variable whose value is subject to variations due to chance (i.e. randomness, in a mathematical sense).:391 A random variable can take on a set of possible different values (similarly to other mathematical variables), each with an associated probability, in contrast to other mathematical variables.

A random variable's possible values might represent the possible outcomes of a yet-to-be-performed experiment, or the possible outcomes of a past experiment whose already-existing value is uncertain (for example, due to imprecise measurements). They may also conceptually represent either the results of an "objectively" random process (such as rolling a die) or the "subjective" randomness that results from incomplete knowledge of a quantity. The meaning of the probabilities assigned to the potential values of a random variable is not part of probability theory itself but is instead related to philosophical arguments over the interpretation of probability. The mathematics works the same regardless of the particular interpretation in use.

The mathematical function describing the possible values of a random variable and their associated probabilities is known as a probability distribution. Random variables can be discrete, that is, taking any of a specified finite or countable list of values, endowed with a probability mass function, characteristic of a probability distribution ; or continuous, taking any numerical value in an interval or collection of intervals, via a probability density function that is characteristic of a probability distribution; or a mixture of both types. The realizations of a random variable, that is, the results of randomly choosing values according to the variable's probability distribution function, are called random variates.

The formal mathematical treatment of random variables is a topic in probability theory. In that context, a random variable is understood as a function defined on a sample space whose outputs are numerical values.

## Definition

A random variable $X\colon \Omega \to E$ is a measurable function from the set of possible outcomes $\Omega$ to some set $E$. The technical axiomatic definition requires $\Omega$ to be a probability space and $E$ to be a measurable space.

Note that although $X$ is usually a real-valued function ($E=\mathbb{R}$), it does not return a probability. Rather, $X$ describes some numerical property that outcomes in $\Omega$ may have. E.g. the number of heads in a random collection of coin flips; the height of a random person. The probability that $X$ is less than or equal to 3 is the measure of the set of outcomes $\{\omega\in\Omega: X(\omega)\leq 3\}$, denoted $\operatorname{P}(X\leq 3).$

The measurability of a random variable $X$ basically means that the events

[$] X^{-1}(a,b] = \{\omega : a \lt X(\omega) \leq b\} [$]

have been assigned a probability.

### Standard case

Usually $E =$ $\mathbb{R}$. When the image (or range) of $X$ is finite or countably infinite, the random variable is called a discrete random variable:399 and its distribution can be described by a probability mass function which assigns a probability to each value in the image of $X$. If the image is uncountably infinite then $X$ is called a continuous random variable. In the special case that it is absolutely continuous, its distribution can be described by a probability density function , which assigns probabilities to intervals; in particular, each individual point must necessarily have probability zero for an absolutely continuous random variable. Not all continuous random variables are absolutely continuous, for example a mixture distribution. Such random variables cannot be described by a probability density or a probability mass function.

### Almost sure equality

Two random variables $X$ and Y are equal almost surely if, and only if, the probability that they are different is zero:

[$]\operatorname{P}(X \neq Y) = 0.[$]

### Equality

Finally, the two random variables $X$ and Y are equal if they are equal as functions on their measurable space:

[$]X(\omega)=Y(\omega)\qquad\hbox{for all }\omega.[$]

## Examples

### Discrete random variable

In an experiment a person may be chosen at random, and one random variable may be the person's height. Mathematically, the random variable is interpreted as a function which maps the person to the person's height. Associated with the random variable is a probability distribution that allows the computation of the probability that the height is in any subset of possible values, such as the probability that the height is between 180 and 190 cm, or the probability that the height is either less than 150 or more than 200 cm.

Another random variable may be the person's number of children; this is a discrete random variable with non-negative integer values. It allows the computation of probabilities for individual integer values – the probability mass function (PMF) – or for sets of values, including infinite sets. For example, the event of interest may be "an even number of children". For both finite and infinite event sets, their probabilities can be found by adding up the PMFs of the elements; that is, the probability of an even number of children is the infinite sum $\operatorname{PMF}(0) + \operatorname{PMF}(2) + \operatorname{PMF}(4) + \cdots$.

In examples such as these, the sample space (the set of all possible persons) is often suppressed, since it is mathematically hard to describe, and the possible values of the random variables are then treated as a sample space. But when two random variables are measured on the same sample space of outcomes, such as the height and number of children being computed on the same random persons, it is easier to track their relationship if it is acknowledged that both height and number of children come from the same random person, for example so that questions of whether such random variables are correlated or not can be posed.

#### Coin toss

The possible outcomes for one coin toss can be described by the sample space $\Omega = \{\text{heads}, \text{tails}\}$. We can introduce a real-valued random variable $Y$ that models a \$1 payoff for a successful bet on heads as follows:

[$] Y(\omega) = \begin{cases} 1, & \text{if} \ \ \omega = \text{heads} ,\\ \\ 0, & \text{if} \ \ \omega = \text{tails} . \end{cases} [$]

If the coin is a fair coin, Y has a probability mass function $f_Y$ given by:

[$] f_Y(y) = \begin{cases} \tfrac 12,& \text{if }y=1,\\ \\ \tfrac 12,& \text{if }y=0,\\ \end{cases} [$]

#### Dice roll

A random variable can also be used to describe the process of rolling dice and the possible outcomes. The most obvious representation for the two-dice case is to take the set of pairs of numbers $n_1$ and $n_2$ from {1, 2, 3, 4, 5, 6} (representing the numbers on the two dice) as the sample space. The total number rolled (the sum of the numbers in each pair) is then a random variable $X$ given by the function that maps the pair to the sum:

[$]X((n_1, n_2)) = n_1 + n_2[$]

and (if the dice are fair) has a probability mass function $f_X$ given by:

[$]f_X(S) = \tfrac{\min(S-1, 13-S)}{36}, \text{for } S \in \{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12\}[$]

### Continuous random variable

An example of a continuous random variable would be one based on a spinner that can choose a horizontal direction. Then the values taken by the random variable are directions. We could represent these directions by North, West, East, South, Southeast, etc. However, it is commonly more convenient to map the sample space to a random variable which takes values which are real numbers. This can be done, for example, by mapping a direction to a bearing in degrees clockwise from North. The random variable then takes values which are real numbers from the interval [0, 360), with all parts of the range being "equally likely". In this case, $X$ = the angle spun. Any real number has probability zero of being selected, but a positive probability can be assigned to any range of values. For example, the probability of choosing a number in [0, 180] is 1/2. Instead of speaking of a probability mass function, we say that the probability density of $X$ is 1/360. The probability of a subset of [0, 360) can be calculated by multiplying the measure of the set by 1/360. In general, the probability of a set for a given continuous random variable can be calculated by integrating the density over the given set.

### Mixed type

An example of a random variable of mixed type would be based on an experiment where a coin is flipped and the spinner is spun only if the result of the coin toss is heads. If the result is tails, $X$ = −1; otherwise $X$ = the value of the spinner as in the preceding example. There is a probability of 1/2 that this random variable will have the value −1. Other ranges of values would have half the probability of the last example.