[Math] Moment Generating Function with Taylor Series

moment-generating-functionsprobabilitysequences-and-seriestaylor expansion

I'm studying moment generating function(MGF). In the video it says The MGF of a random variables(r.v.s.) is $M_x(t) = E (e^{tx})$ and for discrete r.v.s. is $M_x(t) = \sum_x e^{tx} P(X=x)$

I do understand that, for example the MGF of Bernoulli (X~Bern(p)) is $M(t) = E(e^{tX}) = P(X=1)*e^t + P(X=0) * 1 = pe^t + q$

What I do not understand is from the book "Introduction to probability" by Joseph K. Blitzstein and Jessica Hwang page 256 talks about the topic of "Moments via derivatives of the MGF" it says. "Given the MGF of X, we can get the nth moment of X by evaluating the nth derivative of the MGF at $0: E(X^n) = M^{(n)}(0)$
This can be seen by noting that the Taylor expansion of M(t) about 0 is

$$M(t) = \sum_{n=0}^\infty M^{(n)}(0) \frac{t^n}{n!}$$

While on the other hand we also have

$$M(t) = E(e^{tX}) = E(\sum_{n=0}^\infty X^n \frac{t^n}{n!})$$
"

How to go from $E(e^{tX}) $ to $ E(\sum_{n=0}^\infty X^n \frac{t^n}{n!})$ ??? I only know taylor series around 0 (Maclaurin series) of $e^x = \sum _{n=0} ^\infty \frac{x^n}{n!} $ but in this case it is $e^{tX}$ which also involve the r.v.s. X. How to calculate that??? how to take derivative?

Best Answer

I am not sure whether you are looking for
$$E\left[e^{tX}\right] = E\left[\sum_{n=0}^\infty \dfrac{(tX)^n}{n!}\right] = E\left[\sum_{n=0}^\infty X^n \dfrac{t^n}{n!}\right]$$ or want to continue this to $$=\sum_{n=0}^\infty \dfrac{t^n}{n!} E\left[X^n\right] $$

but both use the series for $e^x =1 + x+\frac{x^2}{2!}+\frac{x^3}{3!}+\cdots$ and $(tX)^n=t^n X^n$, while the final equality uses the linearity of expectation