Discrete random variable Consider an experiment where a person is chosen at random. An example of a random variable may be the person's height. Mathematically, the random variable is interpreted as a function which maps the person to their 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 {{tmath| \operatorname{PMF}(0) + \operatorname{PMF}(2) + \operatorname{PMF}(4) + \cdots }}. In examples such as these, the
sample space 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. If \{a_n\}, \{b_n\} are countable sets of real numbers, b_n >0 and , then F=\sum_n b_n \delta_{a_n}(x) is a discrete distribution function. Here \delta_t(x) = 0 for , for . Taking for instance an enumeration of all rational numbers as {{tmath| \{a_n\} }}, one gets a discrete function that is not necessarily a
step function (
piecewise constant).
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}, \\[6pt] 0, & \text{if } \omega = \text{tails}. \end{cases} If the coin is a
fair coin, has a
probability mass function f_Y given by: f_Y(y) = \begin{cases} \tfrac 12,& \text{if }y=1,\\[6pt] \tfrac 12,& \text{if }y=0, \end{cases}
Dice roll plotted as the height of picture columns here. 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
n1 and
n2 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
fX given by: f_X(S) = \frac{\min(S-1, 13-S)}{36}, \text{ for } S \in \{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12\}
Continuous random variable Formally, a continuous random variable is a random variable whose
cumulative distribution function is
continuous everywhere. There are no "
gaps", which would correspond to numbers which have a finite probability of
occurring. Instead, continuous random variables
almost never take an exact prescribed value
c (formally, \forall c \in \mathbb{R}:\; \Pr(X = c) = 0) but there is a positive probability that its value will lie in particular
intervals which can be
arbitrarily small. Continuous random variables usually admit
probability density functions (PDF), which characterize their CDF and
probability measures; such distributions are also called
absolutely continuous; but some continuous distributions are
singular, or mixes of an absolutely continuous part and a singular part. 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 . 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. More formally, given any
interval I = [a, b] = \{x \in \mathbb{R} : a \le x \le b \}, a random variable X_I \sim \operatorname{U}(I) = \operatorname{U}[a, b] is called a "
continuous uniform random variable" (CURV) if the probability that it takes a value in a
subinterval depends only on the length of the subinterval. This implies that the probability of X_I falling in any subinterval [c, d] \sube [a, b] is
proportional to the
length of the subinterval, that is, if , one has \Pr\left( X_I \in [c,d]\right) = \frac{d - c}{b - a} where the last equality results from the
unitarity axiom of probability. The
probability density function of a CURV X \sim \operatorname {U}[a, b] is given by the
indicator function of its interval of
support normalized by the interval's length: f_X(x) = \begin{cases} \displaystyle{1 \over b-a}, & a \le x \le b \\ 0, & \text{otherwise}. \end{cases}Of particular interest is the uniform distribution on the
unit interval [0, 1]. Samples of any desired
probability distribution \operatorname{D} can be generated by calculating the
quantile function of \operatorname{D} on a
randomly-generated number distributed uniformly on the unit interval. This exploits
properties of cumulative distribution functions, which are a unifying framework for all random variables.
Mixed type A
mixed random variable is a random variable whose
cumulative distribution function is neither
discrete nor
everywhere-continuous. It can be realized as a mixture of a discrete random variable and a continuous random variable; in which case the will be the weighted average of the CDFs of the component variables. 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 is the value of the spinner as in the preceding example. There is a probability of that this random variable will have the value −1. Other ranges of values would have half the probabilities of the last example. Most generally, every probability distribution on the real line is a mixture of discrete part, singular part, and an absolutely continuous part; see ''''. The discrete part is concentrated on a countable set, but this set may be dense (like the set of all rational numbers). == Measure-theoretic definition ==