0
$\begingroup$

Assume you have an uniformly distributed random variable $u \in (0,1).$ How can you create a random variable with density

$f(x)=\left\{\begin{matrix} \frac{1}{\pi}\frac{1}{1+x^2}\text{ if }x\geq 0\\ \frac{1}{2}e^x \;\;\;\;\text{ else} \end{matrix}\right. \;\;\;\;$ ?

We first need to know the (cumulative) distribution function of the density function, so we can continue by inverting that distribution function.

The distribution function is $$F(x)=\begin{cases} \frac12e^x & \mbox{if }x < 0 \\ \frac12+\frac1\pi \arctan (x) & \mbox{if } x \ge0 \end{cases}$$

(which is correct because my previous question was about it: Determine the distribution function of this density function).

We are looking for its inverse now (I'm not sure if it's correct like that):

$$i = \frac{1}{2}e^x \Leftrightarrow 2i = e^x \Leftrightarrow x = \ln(2i)$$

$$i=\frac{1}{2}+\frac{1}{\pi} \arctan(x) \Leftrightarrow i-\frac{1}{2}= \frac{1}{\pi}\arctan(x) \Leftrightarrow \pi\left(i-\frac{1}{2}\right)=\arctan(x) \Leftrightarrow \\ \Leftrightarrow x = \tan\left(\pi\left(i-\frac{1}{2}\right)\right)$$

Thus the inverse of the distribution function is $$F^{-1}(i)=\begin{cases} \ln(2i) & \mbox{if }i > 0 \\ \tan\left(\pi\left(i-\frac{1}{2}\right)\right) & \mbox{if } i \le0 \end{cases}$$

Assuming this is correct, how would you get the random variable by this? Is it the maximum possible $i$?

$\endgroup$
  • $\begingroup$ what does it mean create? what does the uniform have to to with X? $\endgroup$ – Hard Core Jan 27 '18 at 21:31
  • 1
    $\begingroup$ @HardCore Actually I wasn't sure how to phrase it :p Maybe I should have rather written "simulate a random variable by the given density" or something like that ;) $\endgroup$ – cnmesr Jan 27 '18 at 21:48
3
$\begingroup$

Observe that if $F(x) = y$ then $y \in [0,1]$. Also, in your case, $F(0) = 1/2$. Therefore, $$F^{-1}(y) = \left\{\begin{matrix}\ln(2y) & \text{if $0 \le y \le \frac{1}{2}$;}\\ \tan\left(\pi\left(y-\frac{1}{2}\right)\right) & \text{if $\frac{1}{2} \le y \le 1$.}\end{matrix}\right.$$

Now, set $X = F^{-1}(U)$, where $U$ is a uniform random variable that takes on values between $0$ and $1$. It is easy to observe that $$F_X(x) = \Pr(X \le x) = \Pr(F^{-1}(U) \le x) = \Pr(U \le F(x)) = F(x).$$ Here, I have used the fact that $F_U(u) = \Pr(U \le u)= u$ for $u \in [0,1]$.

$\endgroup$
3
$\begingroup$

The domain of the inverse is $(0,1)$. The switch between the two pieces of the original CDF is at the $y$ value of $1/2$, so that will be where the switch in the inverse happens. Other than that, your inverse is correct. The point of this is then that if $U$ is $\mathrm{Unif}(0,1)$ distributed then $F^{-1}(U)$ has the distribution of the variable you want. This trick is called the probability integral transformation; it is one of the main ways that random variables are sampled in numerical computation.

$\endgroup$
3
$\begingroup$

If you want a practical answer it is very simple. The theoretical framework you want to look at is called inverse transform method, you can google it.

Once you have obtained the inverse CDF as you did you would use a software to generate random numbers from a uniform between 0 and 1.

The outcome of the simulation is your $i$.

You would therefore feed the outcome of the simulation to the $F^{-1}(i)$ and you are done.

$F^{-1}(i)$ is your random number simulated from the CDF $F$ (basically is your $x$).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.