I have a continuous random variable $X$ whose distribution is conditioned on another discrete random variable $S$. The conditional density function of $X$ is
- $f_{X|S}(x|1) = \alpha e^{-\alpha x}, x \geq 0$
- $f_{X|S}(x|-1) = \beta e^{\beta x}, x \leq 0$
I can see that when $S=1$, $X \sim Exp(\alpha)$ with $\alpha >0$ and when $S=-1$, $-X \sim Exp(\beta)$ with $\beta >0$. That is, $S$ is the sign of $X$.
I then define $Z = |X|$ and I have to calculate $\mathbb{P}(S=1|Z=z)$. I know that this is the posterior probability of $S$ and I can use the Bayes rule for the case of a discrete unknown and continuous observation. The chosen formula is: $$p_{S|Z}(1|z)= \frac{p_S(1)f_{Z|S}(z|1)}{f_Z(z)}$$ and I know from the prior of $S$ that $p_S(1) = p$.
My approach to calculate $f_{Z|S}(z|1)$ would be to consider that, if I know that $S=1$ therefore $Z = X$ and $f_{Z|S}(z|1) = f_{X|S}(x|1)$. What I don't understand is how to come out with the marginal of $Z$. The marginal of $X$ is:
- $p \cdot \alpha e^{-\alpha x}$ when $x \geq 0$
- $(1-p) \cdot \beta e^{\beta x}$ when $x \leq 0$
and my idea here is that the marginal of $Z$ is $p \cdot \alpha e^{-\alpha z} + (1-p) \cdot \beta e^{\beta z}$ since the $|X|$ mirrors $-X$ for the negative part, but I get a bit lost at this point.
EDIT: I also thought that, since $f_{X|S}(x|-1) = \beta e^{\beta x}$ then $f_{Z|S}(z|-1) = \beta e^{-\beta x}$, therefore $$f_Z(z) = p \cdot \alpha e^{-\alpha z} + (1-p) \cdot \beta e^{-\beta z}$$ but I don't know whether this is correct.
For $z \ge 0,$ $$\begin{align*} \Pr[Z \le z] &= \Pr[-z \le X \le z] \\ &= \Pr[-z \le X < 0 \mid S = -1]\Pr[S = -1] + \Pr[0 \le X \le z \mid S = 1]\Pr[S = 1] \\ &= (1 - e^{\beta (-z)})(1-p) + (1 - e^{-\alpha z})p. \end{align*}$$
Therefore, $$f_Z(z) = p \alpha e^{-\alpha z} + (1-p) \beta e^{-\beta z}.$$