0
$\begingroup$

I have this density $f(y|z) = \kappa*\exp(-\kappa y) / (1 - \exp(-\kappa z))$, where $\kappa$ is some known value and $0 < y < \kappa$. I get the distribution by integrating with respect to $y$. I want to sample $y$'s from the resulting distribution and I have tried Markov chain Monte Carlo to do this task. As I am not a statistician and I am reading on my own, I was wondering if there is a better or a simpler way to sample from the resulting distribution. Thank you for any assistance you can provide.

$\endgroup$
2
  • $\begingroup$ If you want to sample $y$, you want to integrate out $z$. This is simple calculus which gives $k C e^{-ky}$, assuming the integral $C$ is finite. Now, you can draw from $e^{-ky}$. $\endgroup$
    – horaceT
    Commented Jun 20, 2016 at 23:58
  • 1
    $\begingroup$ 1. Your stated conditional density doesn't integrate to 1. $\:$ 2. Conditional on $z$, the denominator is a scaling constant, so you simply have a truncated exponential on $(0,\kappa)$ (as you state it); a variety of standard RNG methods will for for that. $\endgroup$
    – Glen_b
    Commented Jun 21, 2016 at 1:01

1 Answer 1

2
$\begingroup$

The density can be integrated with respect to $y$ and then inverted, which allows the inverse transform sampling method https://en.wikipedia.org/wiki/Inverse_transform_sampling to be used to generate random numbers from the distribution having the density $f(y|z)$.

First of all, note that in order to make $f(y|z)$ a proper density, i.e., integrating to 1 over its domain, the needed condition is $0 \le y \le z$, not $0 \lt y \lt \kappa$.

The cumulative distribution $$F(y|z) = -(exp(\kappa*z)-1-exp(-\kappa*(y-z))+exp(-\kappa*y))/((exp(\kappa*z)-1)*(-1+exp(-\kappa*z)))$$ for $0 \le y \le z$. Note that $F(0|z) = 0$ and $F(z|z) = 1$.

This can be inverted, resulting in $$ln(1/(U-exp(\kappa*z)*(U-1)))/\kappa+z$$ as the formula to generate a random number from a distribution having density $f(y|z)$, where $U$ is a random number drawn from a $Uniform[0,1]$ random number generator. For each random number to be drawn from the distribution having density $f(y|z)$, a single value of $U$ is drawn, and this single value is used in both locations in which it appears in the formula.

As can be seen, $U$ values of $0$ to $1$ produce random numbers via the formula ranging from $0$ to $z$.

$\endgroup$
10
  • $\begingroup$ Thank you very much for your reply. I will redo it on my own to see if I got it. Thank you. $\endgroup$
    – Maria
    Commented Jun 21, 2016 at 11:48
  • $\begingroup$ Can I please ask another question? If I want to sample from the conditional distribution of $(Y_{1}+Y_{2}) | (z_{1},z_{2})$ how would I do it? Is it enough to sample $Y_{1}|z_{1}$ and $Y_{2}|z_{2}$ using the inversted formula and then add them? $\endgroup$
    – Maria
    Commented Jun 23, 2016 at 14:19
  • $\begingroup$ I don't know the context of what you are doing. Is there a meaning to $(Y_1+Y_2)|(z_1,z_2)$ other than as $Y_1|z_1 + Y_2|z_2$? $\endgroup$ Commented Jun 23, 2016 at 15:13
  • $\begingroup$ I am trying to understand a bit more. With your answer to my question I am able now to sample $y$'s from the conditional distribution of $y|z$. Now I want to go further and I ask myself. If I sample from $y_{1}|z_{1}$ and name these $W_{1}$ and $y_{2}|z_{2}$ and name these $W_{2}$, how can I get the distribution of the sum $W_{1}+W_{2}$ . I understand that this is a conditional distribution since the $W$'s come from conditional distributions. My previous notation perhaps is not written correctly but I explain now what I am after. Thank you. $\endgroup$
    – Maria
    Commented Jun 23, 2016 at 15:24
  • $\begingroup$ it sounds like you can draw $W_1$ and $W_2$ values separately (independently) and add them as you propose. But as I wrote before, I still don't know your bigger context (any dependency between $Y$ values for different $z$ values?), or some other kind of dependency going on, in which case we need to know more than $f(y|z)$ to define the problem.. $\endgroup$ Commented Jun 23, 2016 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.