# Evaluating a “binomial-like” sum

I suspect there is a way to do the following sum by hand, but I'm having some trouble: $$\sum_{x=0}^{n} x^{2} {n \choose x} p^{x}(1-p)^{n-x}$$

There are a couple questions like this, but for general $x^{k}$, I wanted to know for k = 2.

• $=E(X^2)=(E(X))^2+\sigma^2_X=(np)^2+np(1-p)$ for $X\sim B(n,p)$. For general $k$, you could probably use $k$th derivative of moment generating function for a binomial. – A.S. Mar 19 '16 at 18:22
• @A.S. ya this is how i ended up doing it when i answered orginially – yoshi Mar 19 '16 at 19:05
• I'm assuming $k$ and $n$ are the same thing? And $x$ does not generally represent an integer variable, but that's more of a convention. – Teepeemm Mar 20 '16 at 0:21

\begin{align*} \sum_kk^2\binom{n}kp^k(1-p)^{n-k}&=n\sum_kk\binom{n-1}{k-1}p^k(1-p)^{n-k}\\ &=n\sum_k(k+1)\binom{n-1}kp^{k+1}(1-p)^{n-k-1}\\ &=n\sum_kk\binom{n-1}kp^{k+1}(1-p)^{n-k-1}+n\sum_k\binom{n-1}kp^{k+1}(1-p)^{n-k-1}\\ &=n(n-1)\sum_k\binom{n-2}{k-1}p^{k+1}(1-p)^{n-k-1}+np\sum_k\binom{n-1}kp^k(1-p)^{(n-1)-k}\\ &=n(n-1)\sum_k\binom{n-2}kp^{k+2}(1-p)^{n-2-k}+np\\ &=n(n-1)p^2+np\\ \end{align*}
Take $q$ to be a constant in the following, and use the identity $$\sum_{x=0}^n \left(n\atop x\right)p^x q ^{n - x} = (p +q )^n.$$ Apply the operator $D = p \,{d\over dp}$ to both sides $k$ times (twice, here), and then set $q = 1-p$, and you'll get the same answer (for $k=2$) as is on this page... i.e., $p^2n (n-1) +pn = (pn)^2 + np(1-p).$