# expected value of n-fold p-coin toss

We have n-fold p-coin toss

Y is the number of ordered pairs of tosses in which both result in 1.

I need the expected value of Y where Y is a sum of indicator variables, and a proof that $$E[X(X-1)], \space X\space Bin-(n,p)-$$

Y_i=\left\{ \begin{aligned} 1 && X_i = p\\ 0 && X_i = (1-p) \end{aligned} \right. Any sum of Bernoulli random variables, $S_n=\sum\limits_{i=1}^nY_i$ is a binomial random variable with parameters $n$ and $p$. In other words, for every integer $k$ such that $0\le k\le n$, $$\mathrm P(S_n=k)={n\choose k}p^k(1-p)^{n-k}.$$

But how can I show that the expectation value is $$E[X(X-1)]\space?$$

-
Can you find $g(t) = \sum_{k=0}^n \mathbb{P}(S_n = k) t^k$. Then $\mathbb{E}(X(X-1)) = g^{\prime\prime}(1)$ –  Sasha Nov 23 '11 at 18:02

As Sasha suggested, let \begin{align*} g(x)&=\sum_{k=0}^n \mathbb{P}(S_n=k)x^k\\ &=\sum_{k=0}^n\binom{n}k p^k(1-p)^{n-k}x^k\\ &=\sum_{k=0}^n\binom{n}k(px)^k(1-p)^{n-k}\\ &=(px+1-p)^n \end{align*} by the binomial theorem. Then $$g\;'(x)=\sum_{k=0}^n k\mathbb{P}(S_n=k)x^{k-1}\;,$$
and $$g\;''(x)=\sum_{k=0}^n k(k-1)\mathbb{P}(S_n=k)x^{k-2}\;,$$
so $$g\;''(1)=\sum_{k=0}^n k(k-1)\mathbb{P}(S_n=k)=\mathbb{E}(X(X-1))$$ by definition. On the other hand, you know that $g(x)=p(px+1-p)^n$, so you can calculate $g\;''(1)$ explicitly with a little elementary calculus.