Random variable

A **random variable** is used in mathematics to study probability theory. It was developed to model the chance of events happening in all kinds of real-life scenarios.

## Definition 
Take two measurable spaces, and name them (\Omega_1,\mathcal A_1) and (\Omega_2,\mathcal A_2). A measurable space is any pair of sets, called \Omega and \mathcal A, that follow these rules:
# \Omega is not empty;
# The elements of \mathcal \mathcal A are subsets of \Omega;
# \Omega and the empty set are both elements of \mathcal A;
# \mathcal A is closed under complements and countable unions.
A random variable, named  X , is a measurable function from \Omega_1 to \Omega_2. This is written X:\Omega_1 \to \Omega_2. A random variable is typically represented by capital roman letters such as X, Y, Z and T, and can be either discrete (taking on a countable set of values) or continuous (taking on an interval of values).

The set \Omega_1 is called the sample space. The set \mathcal A_1 is called the event space.

## Use in Probability 
Take a probability measure \mathbb P on (\Omega_1,\mathcal A_1). Take a set A in \mathcal A_2. Then \mathbb P(A) is defined to mean \mathbb P(X^{-1}(A)).

## Examples with Dice 
When you roll a dice, 6 events can happen. These events are the different numbers that can show on the dice: 1, 2, 3, 4, 5, or 6. 

### Dicing Fruit 
Here is an example of a random variable. You roll a fair dice once. If the number on the dice is odd, you eat an apple, and if the number is even, you eat an orange. The random variable is the type of fruit that you will eat. Before you roll the dice, you don't know if you will eat an apple or an orange. We can also write this with mathematics:

Take \Omega_1 = \{1,2,3,4,5,6\}. Take \mathcal A_1 to be the power set of \Omega_1. Take \Omega_2 = \{apple, orange\}. Take \mathcal A_2 to be the power set of \Omega_2. Our random variable follows the even/odd rule from above:
:
X(\omega)= 
\begin{cases}
apple & \text{ if } \omega \text{ is odd}; \\
orange & \text{ if } \omega \text{ is even}. 
\end{cases}

Here  \omega  represents the number on the dice after you roll it. We said the dice is fair. In mathematics, this means  \mathbb P(\{\omega\})=1/6  for  \omega = 1,2,3,4,5 and  6 .

The event that you eat an apple is a set in the event space. It is  \{1,3,5\} . The probability that you eat an apple is the probability measure of this set. It is  \mathbb P(\{1,3,5\})=1/2 .

### Dicing Fruit Unfairly 
Here is another example. Sometimes a dice is unbalanced. This means that it rolls some numbers more often than others. We can do the same experiment as above, but with an unbalanced dice.

For example, let's say that we use a dice that has been changed in one way: it never rolls the number 5. Then you are less likely to eat an apple, because 5 is an odd number. The random variable is *exactly* the same as before:
:
X(\omega)= 
\begin{cases}
apple & \text{ if } \omega \text{ is odd}; \\
orange & \text{ if } \omega \text{ is even}. 
\end{cases}

This is because end possibilities have not changed. After the dice is rolled, you will eat an apple or an orange. You don't know which. What has changed is the *probability* that you eat an apple or an orange. In mathematics, this means
:
\mathbb P(\{\omega\})=
\begin{cases}
1/5 & \text{ if } \omega = 1,2,3,4,6; \\
0 & \text{ if } \omega = 5. 
\end{cases}

The event that you eat an apple is *the same set* as for the fair dice. It is  \{1,3,5\} . But this event is now less likely to happen, because the dice cannot roll a 5. In other words, the probability that you eat an apple is *different* than for the fair dice. It is  \mathbb P(\{1,3,5\}) = 2/5 .

## Probability spaces 
The examples show that a random variable doesn't automatically give probabilities. If we choose \mathbb P  differently, one random variable can give different probabilities. This can be confusing. For this reason, mathematicians often define a random variable on a probability space. The mathematical notation for this is  (\Omega,\mathcal A,\mathbb P). This fixes the probability measure. Then there is no confusion about the probabilities of events.

## Related pages 
* Expected value
* Probability density function
* Random

## References 
## Further reading 
* Klenke, Achim, *Probability Theory: A Comprehensive Course* : Springer (2013)