TITLE: Expected value equals sum of probabilities
QUESTION [8 upvotes]: Let $X$ be a random variable that takes non-negative integer values. Show that, 
$$E[X] = \sum^{\infty}_{k=1}P(X \geq k)$$
I'm having trouble following the solution. Could someone help clarify some steps? Thanks. 
By definition,
$$P(X \geq k) = \sum^{\infty}_{i=k}p_{X}(i)$$ 
Therefore, we substitute to get 
$$\sum^{\infty}_{k=1}P(X \geq k) = \sum_{k=1}^{\infty}\sum_{i=k}^{\infty}p_{X}(i)$$
Now here is where I'm confused.
$$\sum_{k=1}^{\infty}\sum_{i=k}^{\infty}p_{X}(i) = \sum_{i=1}^{\infty}\sum_{k=1}^{i}p_{X}(i) = \sum^{\infty}_{i=1}ip_{X}(i)$$
I don't understand how we are manipulating the summations in the first equality and how we derive $ip_{X}(i)$ in the second equality.

REPLY [6 votes]: \begin{array}
& & 0P(X=0) & + & 1P(X=1) & + & 2 P(X=2) & + & 3P(X=3) & + & \cdots \\[18pt]
= &  &  & P(X=1) & + & P(X=2)  & + & P(X=3) & + & \cdots \\
&  &   &        &  + & P(X=2) & + & P(X=3) & + & \cdots \\
&  &   &        &    &        & + & P(X=3) & + & \cdots\\
& & & & & & &  & + & \cdots
\end{array}
The sum in the first row is $P(X>0)$; that in the second row is $P(X>1)$; that in the third row is $P(X>2)$, and so on.
The equality of
$$
\sum_{k=1}^\infty \sum_{i=k}^\infty \cdots = \sum_{i=1}^\infty \sum_{k=1}^i \cdots
$$
can be seen by observing that both are the sum over the set
$$
\{ (k,i) : 1\le k \le i \}.
$$
The next equality involves a sum of the form $\displaystyle\sum_{k=1}^i a$ where $a$ does not change as $k$ goes from $1$ to $i$, so it is
$$
\underbrace{a+a+a+\cdots+a}_{i\text{ terms}} = ai.
$$