# Moment Generating Function with Taylor Series

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?

$$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
• When we do Taylor approximation of $e^x$ we need to take derivative of $e^x$ and evaluated at 0 which will then become the coefficient of the power series of the function we approximated. but in this case instead of having $e^x$ we have $e^{tX}$ how can I take derivative of this function? is it function of 2 variables? if not, why? and how to take its derivatives? can you please explain in more detail about how to get from $E\left[e^{tX}\right] into E\left[\sum_{n=0}^\infty \dfrac{(tX)^n}{n!}\right]$ in step by step. I'm newbie – user3270418 Mar 8 '17 at 14:59
• The Taylor series $\displaystyle e^x=\sum_{n=0}^{\infty} \frac{x^n}{n!}$ is exact and converges for all real $x$. So provided $E[e^{tX}]$ exists and is finite for the particular $X$ and all real $t$, you can in effect use the substitution $x=tX$ in the Taylor series without any worries. – Henry Mar 8 '17 at 15:18
• is $e^{tX}$ a function of one variable or two? and what is the reason? t I know it is a variable but I'm not sure about X. X are varies but also has a fixed domain and range. If you say it is a function of 2 variable then we need partial derivative but if you treat X as a constant then we can use chain rule for single variable but I really need detail explanation why you treat X as a constant? X is a random variable isn't it? and if it is a random variable then it is a function not a constant? – user3270418 Mar 8 '17 at 15:33
• For a given value of $t$ and a given real random variable $X$, you have $e^{tX}$ as a random variable. If it helps, $e^{X}$ is a random variable and $(e^{X})^t = e^{tX}$ is a random variable for a given value of $t$. – Henry Mar 8 '17 at 15:42
• Almost. But you also need $E[e^{tX}]$ to be real and finite for all real $t$. For example, it is not for a Cauchy distribution or for a log-normal distribution, in the latter case with a failure when $t$ is positive – Henry Mar 8 '17 at 16:47