# What is the expected value of x log(x) of the gamma distribution?

Let $$w(x) = x \log{x}$$

$$x \sim Gamma(\alpha = 3.7, \lambda = 1)$$

Find $$E[w(x)]$$

I have set up the following integral:

$$\int_0^{\infty} x\log{x} \frac{\lambda^{\alpha}}{\Gamma(\alpha)} x^{\alpha -1} e^{-(\lambda)x}dx$$

Brute-forcing it doesn't seem to be working, but I can't find the "trick".

I know from simulation that it should be approximately 5.32, I just need to compare it to the analytical solution.

• you are missing $x^{\alpha-1}$ in the Gamma density
– Lii
Mar 29 '20 at 15:29
• Thank you, unfortunately I have not made that typo on my page - it's still a baffling integral. Mar 29 '20 at 15:37
• The solutions at stats.stackexchange.com/questions/370880 apply with little change.
– whuber
Mar 29 '20 at 18:56
• I’ve used it in my post @whuber Mar 29 '20 at 19:02
• @gunes Yes, I noticed that after posting my comment (and upvoted your answer, btw).
– whuber
Mar 29 '20 at 19:08

\begin{align}E[X\log X]&=\int_0^\infty \log x \frac{\lambda^\alpha}{\Gamma(\alpha)}x^\alpha e^{-\lambda x}dx\\&=\frac{\Gamma(\alpha+1)}{\Gamma(\alpha)\lambda}\int_0^\infty\log x\frac{\lambda^{\alpha+1}}{\Gamma(\alpha+1)}x^{(\alpha+1)-1}e^{-\lambda x}dx\\&=\frac{\Gamma(\alpha+1)}{\Gamma(\alpha)\lambda}E[\log Y]\end{align} where $$Y\sim \text{Gamma}(\alpha_y=\alpha+1, \lambda_y=\lambda)$$. From here, the expected value of the logarithm of a gamma RV is: $$E[\log Y]=-\log\lambda+\psi(\alpha+1)$$ where $$\psi$$ stands for polygamma function.
So, the overall result is (put $$\alpha=3.7, \lambda=1$$): $$E[X\log X]=\underbrace{\frac{\Gamma(4.7)}{1\times\Gamma(3.7)}}_{3.7}(-\log 1 +\psi(4.7))\approx5.32$$
I've used Matlab's psi function to calculate the polygamma function.