Suppose $X$ has a binomial distribution with success probability $p$ and $n$ trials and let $h(\cdot)$ be a positive convex real-valued function.


Is the function $g(p)=\mathbb{E}[h(X)\ |\ p]$ convex in $p$?


Related questions:
[Binomial Expectation of Convex Function](https://mathoverflow.net/questions/120636/binomial-expectation-of-convex-function) and [expected values over binomial distributions](https://mathoverflow.net/questions/21858/expected-values-over-binomial-distributions)


Note: Based on trial-and-error analysis, it appears to be convex. If anyone is interested, I can send them a spreadsheet with some numbers.



Is the Binomial Expectation of Convex Function Convex in p?
Here is my original answer (see below for a better one):


Writing down
\[
 g(p) = \sum\_{k=0}^n h(k)\binom{n}{k}p^k(1-p)^{n-k}
\]
and differentiating twice gives
\[
 g''(p) = \sum\_{k=0}^n h(k)\binom{n}{k} \\
\cdot \left[ k(k-1)p^{k-2}(1-p)^{n-k} - 2k(n-k)p^{k-1}(1-p)^{n-k-1} + (n-k)(n-k-1)p^k(1-p)^{n-k-2}\right].
\]
Reindexing the three terms of the summation separately with substitutions $k = l+2$, $k=l+1$, and $k=l$, respectively, gives
\[
 g''(p) = \sum\_{l=0}^{n-2} p^l(1-p)^{n-l-2}\bigg[h(l+2)\binom{n}{l+2}(l+2)(l+1) \\ -2h(l+1)\binom{n}{l+1}(l+1)(n-l-1) + h(l)\binom{n}{l}(n-l)(n-l-1)\bigg],
\]
and after some canceling we get
\[
g''(p) = \sum\_{l=0}^{n-2}\left[h(l+2)-2h(l+1)+h(l)\right]\frac{n!}{l!(n-l-2)!}p^l(1-p)^{n-l-2}.
\]


So $g$ is convex on the interval $[0,1]$ whenever the second differences of $h$ (the bracketed terms) are nonnegative, e.g. when $h$ is a convex function on $\mathbb{R}$.




---


A better way to do this is to define the forward difference operator $\Delta$ by $(\Delta h)(l) = h(l+1) - h(l)$. Then calculations similar to, but simpler than, the ones above yield the equation
\[
\frac{d}{dp}\mathbb{E}\_{X\sim \textrm{Binom}(n,p)}h(X) = n\mathbb{E} \_{X\sim \textrm{Binom}(n-1,p)} (\Delta h)(X).
\]
Applying this twice gives the desired result.


