Generating random variables from a mixture of Normal distributions and Exponential distribution using composition method How can I sample from a mixture distribution in particular a mixture of Normal distributions and Exponential distribution in R using composition method?
For instance if I want to sample from:
$0.3\textrm{Exp}(1)+0.5\textrm N(0,1)+0.2\textrm N(4,1)$.
The algorithm should be following:

*

*Generate random number $N$ with distribution $\left \{ \frac{a_n}{n+1} \right \}$

*Generate random number $X$ with probability distribution $g_N(x)$. Using inverse transformation we get: $Y\sim U(0,1) \Rightarrow Y^{\frac{1}{N+1}}\sim g_N$.

I do not know understand how to get $N.$

Let me rephrase the problem as follows:
Question In order to sample $X$ from $$0.3\,\mathcal Exp(1)+0.5\, \mathcal N(0,1)+0.2\,\mathcal N(4,1)\tag{1}$$
a. Write $\text{Prob}(X\le x)$ as
$$0.3\,\text{Prob}(X_1\le x)+0.5\,\text{Prob}(X_2\le x)+0.2\,\,\text{Prob}(X_3\le x)$$
and specify the distributions of the three random variables $X_1,X_2,X_3$
b. Identify an integer-valued random variable $Z$ such that

*

*$Z\in\{1,2,3\}$ with probability one

*$X|Z\sim\begin{cases}X_1 &\text{if }Z=1\\X_2 &\text{if }Z=2\\X_3&\text{if }Z=3\\\end{cases}$

*$X$ is marginally distributed as (1).

c. Conclude with a generation of $X$ based on the joint generation of $(Z,X)$.
