[Math] Plot the cdf and simulate a random variable (rv) with this cdf using the inversion method.

probabilityprobability distributionssimulationstatisticsuniform distribution

Consider the continuous random variable with pdf given by:

$$f(x) = 2(x − 1)^2;\quad 1 < x ≤ 2$$
$$f(x) = 0;\quad \text{otherwise}$$

Plot the cdf for this random variable.
Show how to simulate a rv with this cdf using the inversion method.

I tried this as

$$F(x) =\int_{1}^{x} 2(t − 1)^2 dt=\frac{2}{3}(x − 1)^3;\quad 1 < x ≤ 2$$

I plot the cdf using R.

 x<-seq(1,2,length=10)
 plot(x,(2/3)*(x-1)^3)

to simulate a rv with this cdf using the inversion method

let

$$S=\frac{2}{3}(x − 1)^3$$

$$\frac{3S}{2}=(x − 1)^3$$

$$X=1+{(\frac{3S}{2})}^{\frac{1}{3}}$$

Using R

  X.sim <- function(S)1+(3*S/2)^(1/3)
  S <- runif(100)   

  x = X.sim(S)

But i got the value of $x$ more than $2$ . But $1 < x ≤ 2$ .

How can i solve the problem ?

I noticed if i integrate the pdf under the range $1 < x ≤ 2$ it is not equal to $1$.

Best Answer

The issue is that the normalizing constant has been incorrectly specified in the exercise. It says 2 when it should in fact be 3. See below.

$$ \int_1^2c(x-1)^2dx=c\left[\frac{(x-1)^3}{3}\right]_1^2=\frac{c}{3}=1\Leftrightarrow c=3 $$

If you change this and run the following code:

X.sim <- function(S)1+(S)^(1/3)
S <- runif(100000)   
x <- X.sim(S)
max(x)

you will see that you get very close to 2, but you won't exceed it. Hope this helps!

Related Question