While studying for my exam I came across a problem:
Given the pdf: $f(x) = \frac{x}{\theta} \exp\left(-\frac{x^2}{2} \theta\right),$ generate distribution from $U[0,1]$.
Here is how I would solve it:
To generate the distribution I need to convert the given probability density function (PDF) $f(x)$ into the corresponding cumulative distribution function (CDF) $F(x) = P( X =< x )$. We find the inverse of the $F(x)$. Then we generate a sequence $X_i$ from the uniform distribution, let $X_i = Q(U_i)$, then generated random variables are generated from a distribution with the given density function $f(x)$.
However, in order to obtain $F(x)$ from $f(x)$ integration is required. I run into two problems here:
- How to integrate the expression $f(x) = \frac{x}{\theta} \exp\left(-\frac{x^2}{2} \theta\right)$?
- And how do I determine the upper and lower bound of the integral?
Is this a way to go? or am I doing this all wrong?
EDIT:
Is it possible that Gamma distribution is the solution to my problem? I have tried to use the $\text{Gamma}(1,2{\theta}$) which then yields
$g^{-1} = -\log(y)\times 2\theta$
Your approach sounds good to me.
To integrate $\frac{y}{\theta}\exp {(-\frac{y^2}{2}\theta)}$, I would substitute $u = \frac{y^2}{2}\theta$. Then $du = y\theta\ dy$.
Thus $$F(x) = \int_{-\infty}^x \frac{y}{\theta}\exp {(-\frac{y^2}{2}\theta)}\ dy = \int_{-\infty}^{\frac{x^2}{2}\theta} \frac{y}{\theta}\exp {(-u)} \frac{1}{y\theta}\ du = \frac{1}{\theta^2}\int_{-\infty}^{\frac{x^2}{2}\theta}\exp(-u)\ du,$$ which is easier to solve.