The expectation, or expected value, of a random variable is simply its probability-weighted average value ($\mu_x$).
In the discrete case, the expected value is
$E(X) = \displaystyle \sum_{x}^\infty x * P(X=x))$
In the continuous case, the expected value is
$E(X) = \int\limits_{-\infty}^{\infty}x \ f(x) \ dx$
where $f(x)$ is the [[probability density function]].
## Properties of expectations
If c is constant, then $E(c) = c$.
If $a$ and $c$ are constants and $X$ is a random variable, then
$E(aX + c) = aE(x) + c$
Expectation is a linear operator, in other words
$E(aX + bY + c) = aE(x) + bE(Y) +c$
If $g(X)$ is any function of $X$, then $E(g(X)) = \sum_{x=1}^\infty g(x) P(X=x))$This is described more by the [[Law of the Unthinking Statistician]].
## deriving expectation of a discrete variable
Continuing the example from deriving the [[probability mass function]], let's derive the expectation of the [[first success distribution]]. Recall our pmf is defined as
$P(X=x) = (1-p)^{x-1} * p$
We can plug this into our equation for expectation.
$E(X) = \sum_{x=1}^\infty x * p(1-p)^{x-1}$
Recall from the [[geometric series]] that
$\sum_{k=1}^\infty ar^{k-1} = \frac{a}{1-r} \text {, where r<=1}$
We can find the [[derivative]] of both sides with respect to $r$ to find
$\sum_{k=1}^\infty a(k-1)r^{k-2} = \frac{a}{(1-r)^2}$
Observing that when $k=1$, the left side of the equation will be $0$, we can find simply step up the sum to begin from $k=2$.
$\sum_{k=2}^\infty a(k-1)r^{k-2} = \frac{a}{(1-r)^2}$
We can then reindex with $k-1 = j$ to get
$\sum_{j=1}^\infty ajr^{j-1} = \frac{a}{(1-r)^2}$
Notice that the left side of the equation is now the exact same form as the equation for expectation with $a=p$ and $r = 1-p$, so we can substitute the right side of the equation in for expectation.
$E(X) = \sum_{x=1}^\infty x * p(1-p)^{x-1} = \frac{a}{(1-r)^2} = \frac{p}{(1-(1-p))^2} = \frac1p$
This was quite a bit of work to work out the expectation of a discrete random variable! In practice, expectations for specific distributions can be found using lookup tables for common distributions.