# Random Variables, Expectation, Variance

Now that we know a bit about probability distributions, we can discuss the concepts of a **random variables, expectation, and variance**. While these concepts apply to all probability distributions, we will discuss each one in the context of the Bernoulli coin flip example, where we win 1 point for flipping heads and 0 points for flipping tails on a fair coin.

#### Random variable

A random variable represents the outcome of drawing once from the probability distribution upon which it is defined.&#x20;

In our example, let the number of points we win from a fair coin flip be represented by the random variable, X. X is equal to 1 point with 0.5 chance and 0 points with 0.5 chance. Random variables are denoted by capital letters.

#### Expectation

The expectation of a random variable is the mean (or average) value the random variable takes, according to its probability distribution. In other words, it is a weighted average of the possible values of a random variable, where each value is weighted by its probability. Here is the expectation of a Bernoulli random variable.

$$
E(X) = 0\*(1-p) + 1\*p = p
$$

{% tabs %}
{% tab title="Question" %}
In our example, we win 1 point if we flip heads and 0 points if we flip tails on our fair coin. What is the expected number of points won in our coin flip example?
{% endtab %}

{% tab title="Answer" %}
The expectation is 0.5\*1 + 0.5 \*0 = 0.5 points because half of the time we win 1 point and the other half of the time we win 0 points.&#x20;
{% endtab %}
{% endtabs %}

#### Variance

The variance of a random variable is a measurement of how much the outcomes of the random variable differ from its expectation. It is defined as the expectation over the squared differences of each outcome from the mean. Written mathematically, the definition of variance for a Bernoulli random variable is:

$$
var(X) = (1-p)*(0 - E(X))^2 + p*(1-E(X))^2
$$

{% tabs %}
{% tab title="Question" %}
What is the variance of points won in our coin flip example?
{% endtab %}

{% tab title="Answer" %}
0.5\*(0-0.5)^2 + 0.5\*(1-0.5)^2 =  0.25
{% endtab %}
{% endtabs %}

#### Standard Deviation

The standard deviation is the square root of the variance. Note that calculating the variance involves squaring the values of the random variable; this means that the variance is in the squared units of the random variable. We use the standard deviation to discuss variance in the same units as the random variable.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://otd.gitbook.io/book/central-limit-theorem/probability-distributions/random-variables-expectation-variance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
