Linearity of expectation (source code)

= Linearity of expectation
{title2=$\mathbb E[aX+bY]=a\mathbb E[X]+b\mathbb E[Y]$}

For <integrable random variables> $X_1,\ldots,X_n$ on the same <probability space> and fixed <real numbers> $a_1,\ldots,a_n$, <linearity of expectation> states
$$
\mathbb E\!\left[\sum_{i=1}^n a_iX_i\right]=\sum_{i=1}^n a_i\mathbb E[X_i].
$$
The <random variables> can be <dependent random variables>. The formula follows by the <linearity of integration>; a finite <linear combination> of <integrable random variables> remains <integrable>. For example, if $X$ takes $-1,2,8$ with <probabilities> $1/2,3/10,1/5$, then $X$ and $2X$ are <dependent random variables>, yet $\mathbb E[X+2X]=3\mathbb E[X]=5.1$.

An especially useful application counts how many <events> occur. Put $I_i=\mathbf1_{A_i}$, an <indicator random variable>, and $N=\sum_iI_i$. Since $\mathbb E[I_i]=\mathbb P(A_i)$, we get $\mathbb E[N]=\sum_i\mathbb P(A_i)$. There is no need to compute the whole <probability distribution> of $N$, or to assume <independence>. For a <uniform random permutation> of $n\geq1$ objects, each object stays fixed with <probability> $1/n$, so the <fixed point count of a uniform random permutation> has <expected value> one for every $n$. https://ocw.mit.edu/courses/6-042j-mathematics-for-computer-science-spring-2015/mit6_042js15_textbook.pdf[Lehman, Leighton and Meyer, Mathematics for Computer Science, §18.5: linearity and sums of indicators]{ref}.

<Linearity of expectation> concerns <addition> and multiplication by fixed <scalars>. Products instead satisfy $\mathbb E[XY]=\mathbb E[X]\mathbb E[Y]$ under the hypotheses of <expectation of a product of independent random variables>. For the example above, $\mathbb E[X^2]=14.5$, whereas $(\mathbb E[X])^2=2.89$. Applying a nonlinear <function> before averaging can therefore change the answer substantially; use the <law of the unconscious statistician> to compute that average.