Variance of a piecewise pdf There is a $95\%$ chance of event A happening and a $5\%$ chance of event B happening. Event A and B are exclusive so both cannot happen, it's one or the other. The pdf of event A is $f(x)=5e^{-5y}$ and the pdf of event B is $f(y)=7e^{-7y}$. What is the variance when an event is triggered?
This question is basically a piecewise pdf. But i'm not sure how to tackle this one. I started of buying finding and overall E(Y). But how would I utilize that to find Var(Y)?
 A: This is a mixture distribution known as the hyperexponential distribution (which in general is a convex combination of exponential distributions). The density of this distribution (call the random variable $X$) is $f_X(t) = \frac{19}{20}5e^{-5t} + \frac1{20}7e^{-7t}$. We may compute the moment-generating function of $X$ by integration:
\begin{align}
M_X(\theta)  &= \mathbb E[e^{\theta X}]\\ &= \int_0^{\infty } \left(\frac{19}{20} e^{-5t} +\frac1{20} 7 e^{-7t}\right) e^{\theta t} \, dt\\
&= \frac{19}{4 (5-\theta)}+\frac{7}{20 (7-\theta)},\ \mathsf{Re}(\theta)<5.
\end{align}
It follows then that
\begin{align}
\mathbb E[X] &= \lim_{\theta\to 0} \frac{\mathsf d}{\mathsf d\theta} M_X(\theta) = \frac{69}{350},
\end{align}
\begin{align}
\mathbb E[X^2] &= \lim_{\theta\to 0} \frac{\mathsf d^2}{\mathsf d\theta^2} M_X(\theta) = \frac{478}{6125},
\end{align}
and hence
\begin{align}
\mathsf{Var}(X) = \mathbb E[X^2] - \mathbb E[X]^2 = \frac{4799}{122500}\approx 0.0391755.
\end{align}
A: It is not a piecewise pdf but a "Mixture pdf". In particular, it is a linear combination of two Negative Exponential distributions
$$f_Y(y)=0.95\cdot Exp(5)+0.95\cdot Exp(7)$$
whose variance is
EDIT: Considering that for an exponential distribution $Exp(\theta)$ the simple moments are
$$\mathbb{E}[X^k]=\int_0^{-\infty}x^k \theta e^{-\theta x}dx=\frac{1}{\theta^k}\int_0^{-\infty}(x \theta)^k e^{-\theta x}d(x\theta)=\frac{1}{\theta^k}\Gamma(k+1)=\frac{k!}{\theta^k}$$,
the fastest way to get $\mathbb{V}[Y]$ is the following
$$\mathbb{V}[Y]= 0.95\cdot \frac{2}{5^2}+0.05\cdot \frac{2}{7^2}  -[ 0.95\cdot \frac{1}{5}+0.05\cdot \frac{1}{7}]^2 \approx 0,0391755102040816$$
