Derivation of MGF of a squared random variable X~N(0, 1)

Consider a continuous random variable $Y = X^2$ such that $X\sim N(0, 1)$. The PDF of this variable is $f_Y(x)= \dfrac{1}{\sqrt{2\pi}} x^{-\frac12}e^{-\frac{x}{2}}$ as discussed in this post.

According to Wikipedia, the MGF of a random variable X is defined to be $M_X(t) = E[e^{tX}]$. So, naturally, the MGF of Y should be $$M_Y(t) = E[e^{tY}] = E[e^{tX^2}] = \int_{-\infty}^\infty e^{tx^2}f_Y(x)dx = \frac{1}{\sqrt{2\pi}} \int_{-\infty}^\infty e^{tx^2}x^{-\frac12}e^{-\frac{x}{2}}\,dx$$

However, this integral doesn't converge, and pretty much every resource I can find is saying that this integral should just be $\dfrac{1}{\sqrt{2\pi}}\displaystyle \int_{-\infty}^\infty e^{tx^2}e^{-\frac{x^2}{2}}dx$ , which does indeed evaluate to the correct MGF of $M_Y(t) = (1 - 2t)^{-\frac12}$

Why is the PDF of $X$ used for the expected value of $e^{X^2}$ instead of the PDF of $X^2$?

• Because of the law of the unconscious statistician. When you use the pdf of $Y$ it should be $e^{tx}$ instead of $e^{tx^2}$. And integration should be $0$ to $\infty$ in that case. – StubbornAtom May 22 '18 at 2:59
• Shouldn't you be using $f_X(x)$ rather than $f_Y(x)$? Note your domain of integration. – AnyAD May 22 '18 at 2:59
• @StubbornAtom That makes sense, thank you. Why would integration be 0 to ∞ though? Wouldn't you still want to cover all values of x? Apologies for the misunderstanding, I'm fairly new to this. – Nathan G. May 22 '18 at 3:07
• If $x\in\mathbb R$, then $y=x^2\geq 0$. – StubbornAtom May 22 '18 at 3:14
• @StubbornAtom Of course. Thanks! – Nathan G. May 22 '18 at 3:24

While earning a doctorate in statistics I never knew the name "law of the unconscious statistician", but of course I knew the proposition, and nowadays that appears to be what some call it. $$\operatorname E(g(X)) = \begin{cases} \displaystyle \int_{-\infty}^\infty g(x)f_X(x)\,dx. & \text{(This one is the “law of the unconscious statistician.'')} \\[10pt] \displaystyle \int_{-\infty}^\infty xf_{g(X)} (x) \,dx. \end{cases}$$ Sometimes direct evalution of the first integral above is simpler than direct evaluation of the second.
Thus $$\operatorname E(e^{tY}) = \int_{-\infty}^\infty e^{tx} f_Y(x) \, dx = \int_{-\infty}^\infty e^{tx^2} f_X(x)\, dx = \int_{-\infty}^\infty x f_{e^{tX^2}}(x) \, dx.$$