Suppose $X$ be random variable with the pdf $f(x)=2x,0\leq x \leq 1.$ How can we simulate $n$ independent instantiations of $X$?Thanks for any answers/hints.Suggestions of relevent books or tutorials are also welcom
Asked
Active
Viewed 29 times
1 Answers
1
Here is one way using inverse transform sampling.
The cdf of $X$ is $F(x)=x^2$ on $[0,1]$ and 0 else. Hence, the quantile function $F^{-1}:[0,1]\to\mathbb{R}$ is given by $F^{-1}(y)=\sqrt{y}$.
- First generate $n$ independent numbers $u_1,u_2,\ldots,u_n$ from a uniform distribution on $[0,1]$.
- For each $i=1,2,\ldots,n$ calculate $x_i:=F^{-1}(u_i)=\sqrt{u_i}$.
The resulting $x_1,x_2,\ldots,x_n$ are iid observations from the distribution of $X$.
This works because for any cdf $F$ with quantile function $F^{-1}$ and a uniform random variabel $U$ on $[0,1]$, we have for $x\in\mathbb{R}$ $$P(F^{-1}(U)\leq x)=P(U\leq F(x)) = F(x).$$
In R you could do this as follows:
x <- runif(n)
x <- sqrt(x)
Toni
- 927
-
lots of thanks for the beautiful answer! – AgnostMystic May 19 '20 at 03:42