A random variable that takes other random variables as value So suppose I have a random variable $X$, which with probability $p$ is another r.v $X_1$ that is exp($\lambda_1$) and with probability $1-p$, is $X_2$ which is exp($\lambda_2$). Assume $X_1$ and $X_2$ independent.  
Then if I wanted the probability distribution function of $X$, can I just take $f_X(x) = pf_{X_1}(x) + (1-p)(f_{X_2}(x))$ ?. If so, does this generalize to other R.V's (not exp, not independent). 
I think this is incorrect, but I'm trying to solve this problem and if this doesn't hold, I have no idea what to do. :( Thanks for any input !
 A: Let $X_1$ and $X_2$ be continuous random variables.
Define $X$ as follows: with probability $p$ set $X=X_1$,
otherwise set $X=X_2$.
Let $A$ be the event that the value of $X$ is taken from $X_1$.
Then $P(A) = p$ and $P(A^\complement) = 1 - p.$
Assume $A$ is independent of $X_1$ and independent of $X_2$.
Then 
$$\begin{eqnarray}
F_X(x) &=& P(X \leq x) \\
&=& P((A \cap (X_1 \leq x)) \cup (A^\complement \cap (X_2 \leq x))) \\
&=& P(A \cap (X_1 \leq x)) + P(A^\complement \cap (X_2 \leq x)) \qquad
\mbox{because $A$ and $A^\complement$ are disjoint}\\
&=& p\,P(X_1 \leq x) + (1 - p)\, P(X_2 \leq x) \qquad
\mbox{because $A$ is independent of $X_1,X_2$}\\
&=& p\,F_{X_1}(x) + (1 - p)\, F_{X_2}(x).
\end{eqnarray}$$
It follows that
$$\begin{eqnarray}
f_X(x) &=& \frac{d}{dx} F_X(x) \\
&=& \frac{d}{dx} \left( p\,F_{X_1}(x) + (1 - p)\, F_{X_2}(x) \right) \\
&=& p\, \frac{d}{dx} F_{X_1}(x) + (1 - p)\,\frac{d}{dx} F_{X_2}(x)  \\
&=& p\, f_{X_1}(x) + (1 - p)\, f_{X_2}(x).
\end{eqnarray}$$
The fact that $X_1$ and $X_2$ are continuous random variables allows us
to take their derivatives (and allows us to describe $X_1$, $X_2$ and $X$
by density functions alone rather than requiring something else).
In the derivation above, however, we never make use of any knowledge of
which continuous distributions  $X_1$ and $X_2$ have.
We also never rely on the independence of  $X_1$ and $X_2$.
So yes, this generalizes to other continuous random variables and to
the case where $X_1$ and $X_2$ are not independent.
But we did use the assumption that $A$ is independent of $X_1$ as
well as the assumption that $A$ is independent of $X_2$.
This is essential.
Consider a variable $Y$ that is defined as
$$
Y = \begin{cases}
 X_1 &\mbox{if } X_1 \leq x_0, \\
 X_2 &\mbox{if } X_1 > x_0
\end{cases}$$
where $x_0$ is the solution of $F_{X_1}(x_0) = p$, and $p < 1.$
This is similar to $X$ except that in place of $A$ we use the event that $X_1 \leq x_0.$
For any $x \leq x_0$, we can try to write equations for $F_Y$ similar to the
sequence of equations we wrote for $F_X$, but this time we find that
$$\begin{eqnarray}
F_Y(x) &=& P((X_1 \leq x_0) \cap (X_1 \leq x)) + P((X_1 > x_0) \cap (X_2 \leq x)) \\
       &=& P(X_1 \leq x) + P((X_1 > x_0) \cap (X_2 \leq x)).
\end{eqnarray}$$
If we also assume $X_1$ and $X_2$ are independent, then $x \leq x_0$ implies
$$\begin{eqnarray}
F_Y(x) &=& P(X_1 \leq x) + (1 - p)\, P(X_2 \leq x) \\
       &=& F_{X_1}(x) + (1 - p)\, F_{X_2}(x) \\
       &>& p\, F_{X_1}(x) + (1 - p)\, F_{X_2}(x),
\end{eqnarray}$$
so the desired equation is violated. 
