# Expectation value with respect to the binomial distribution

How do I compute the following expectation value concerning the Digamma function $\psi(k)$:

$$\langle k\, \psi(k)\rangle=\sum_{k=0}^n {n\choose{k}}\,p^k(1-p)^{n-k}\, k \,\psi(k)$$

I have tried:

Sum[Binomial[n, k] p^k (1 - p)^(n - k) k PolyGamma[k], {k, 0, n}]


but that gives

$$-(1-p)^n$$

which can not be true.

EDIT:

The closed form solution for $n\geq 1$ is

$$\langle k\, \psi(k)\rangle=p\, n\left(\log p+\psi(n)+B_{1-p}(n,0)\right)-(1-p)^n$$

In Mathematica code:

f[p_,n_] = p n (Log[p] + PolyGamma[n] + Beta[1-p,n,0]) - (1-p)^n

• I wonder if you can't get there from here: PolyGamma = ComplexInfinity. Changing Sum to Table and putting in a specific value for n might shed some light on the issue. – JimB Jun 26 '18 at 22:47
• Might one avoid the PolyGamma problem by summing over k=1 to n, since the k=0 term does not add to the summation? – David G. Stork Jun 26 '18 at 22:51
• @DavidG.Stork That would avoid the Polygamma problem but then a truncated binomial distribution would need to be used. Otherwise it would not be the expectation if the sum of the probabilities don't add up to 1. – JimB Jun 26 '18 at 23:07

For n == 0evaluate the limit

Limit[Binomial[0, k] p^k (1 - p)^-k k PolyGamma[k], k -> 0]

(* -1 *)


Include assumptions

ex[n_, p_] =
Assuming[{0 <= p <= 1, Element[n, Integers], n > 0},
Sum[Binomial[n, k] p^k (1 - p)^(n - k) k PolyGamma[k], {k, 0, n}] //
Simplify] Although the assumptions excluded n == 0, evaluating this expression for n == 0 is consistent with the limit above

ex[0, p]

(* -1 *)

{#, ex[#, p]} & /@ Range[0, 10] //
Simplify //
Prepend[#,
Style[#, 14, Bold] & /@ {"n",
"〈k ψ(k)〉"}] & //
Grid[#, Frame -> All] & Plot[Evaluate@Table[Tooltip[ex[n, p], n], {n, 10, 0, -2}], {p, 0, 1},
PlotLegends -> Placed[Range[10, 0, -2], {0.25, 0.65}],
AxesLabel -> (Style[#, 14, Bold] & /@ {"p",
"〈k ψ(k)〉"})] Note that if the assumptions include n >= 0 then the result is the same as that without assumptions.

Assuming[{0 <= p <= 1, Element[n, Integers], n >= 0},
Sum[Binomial[n, k] p^k (1 - p)^(n - k) k PolyGamma[k], {k, 0, n}] //
Simplify]

(* -(1 - p)^n *)

• But your figure shows that the expectation is not $-(1-p)^n$ (except for $n=0$). What am I missing? – JimB Jun 27 '18 at 3:40
• @JimB - The last observation reflects how Mathematica might arrive at its result. I understand that the results are different under the different assumptions. – Bob Hanlon Jun 27 '18 at 3:57
• OK. Got it now. It does seem that using Limit[k PolyGamma[k], k->0] = -1 for k PolyGamma[k] when k=0 for all values of n gives what you show in the table and figure. – JimB Jun 27 '18 at 4:03

The problem is that PolyGamma[k] has a simple pole in zero, i.e. PolyGamma[k] ~ -1/k +O(1). Therefore k*PolyGamma[k] is regular in zero and has value -1.

For your purpose you could define a function regular in zero, say

jj[x_] := Piecewise[{{-1, x <= 0}, {x*PolyGamma[x], x > 0}}]


So that the expectation value of jj i.e.

Sum[Binomial[n, k] p^k (1 - p)^(n - k) jj[k], {k, 0, n}]


is OK for n=0. This method reproduces the above table.

For generic n there is no simple expression. One could however easily infer that

Sum[n] ~ -1 -n*(EulerGamma-1)*p + O(p^2)