# Joint probability of two distributions

If I have one random variable that represents hours worked per job X~exponential($$\theta$$). I have another random variable that represents how many jobs obtained per month Y~Poisson($$\lambda$$). Using bayes I have used inverse gamma on the exponential and gamma on the Poisson. I now have two gamma distributions. How would I now use those distributions that obtain the probability that the total number of hours worked in a year is Z? p(Z>2000) for example? I imagine I have to use joint probabilities such that $$X \times Y > 2000$$ and divide that by the total joint probabilities of the two distributions. Given that I have obtained these two distributions? Does anybody know how I would do this in R?

would I be using dgamma for each distribution? How would I then multiply them together to get the total range of possible total hours worked?

I have to multiply all the possible values of one distribution by all the possible values of the other distribution, so I imagine with my two random variables, my function would look like this.

$$f_{XY}(x,y) = xy$$

$$f_{XY}(x,y) = \text{dgamma()*dgamma()}$$ with appropriate parameters?

So I want something like

$$P(X \times Y > 2000) = \int\int f_{XY}(x,y)dxdy$$

$$P(X \times Y > 2000) = \int\int xy \: dxdy$$

Can anyone help?

• You don't have enough information to obtain a unique answer or even a narrow range of them. You need to know or make strong assumptions about how the variables are associated. – whuber Oct 2 '18 at 15:09
• I see @whuber. The only assumptions are that months are 30 days each really. if the mean number of jobs coming through is 15 and the mean length of a job is say 4 hours. i'm not sure what other assumptions I would need, but I have not been given any others for this question, except for independence and stationary increments. – Bucephalus Oct 2 '18 at 15:26
• Independence is a very strong assumption (and likely not realistic in this case) and hasn't been stated in your question. – whuber Oct 2 '18 at 15:31
• Yes, @whuber, a lot of undergrad university questions are not realistic, agreed. They are merely designed for pedagogical purposes. – Bucephalus Oct 2 '18 at 15:34
• For this to make any sense, you'd be generating a different exponential variate for each job, not the same one (why would every job take exactly the same time?) -- so not $X\times Y$ but $\sum_{i=1}^Y X_i$. – Glen_b -Reinstate Monica Oct 2 '18 at 15:52

Total number of hours per year (Z) is a function dependent on the number of hours per job and the number of jobs per months (and we have 12 months).

Z = X(Y(12))


I would use iterate some this expression with your lambdas and rates:

rexp(rpois(12, lambda = 0.5), rate = 0.2)


To estimate the distribution of Z, and then calculate the probability of Z > 2000 from that distribution. Also, as sanity check, the total amount of hours cannot be above 365*24, so I would delete any estimation above 8760 hours of threshold. Example:

iterations <- 1000
Z <- vapply(seq_len(iterations), function(x){sum(rexp(rpois(12, lambda = 0.5), rate = 0.2))}, numeric(1L))
hist(Z) And then you can calculate the probability with sum(Z >2000)/length(Z)

• Thanks @Llopis. That's helpful. But I have to use the bayesian posterior I believe, to satisfy this question. – Bucephalus Oct 2 '18 at 15:23
• I don't understand why you need the posterior probability. Could you explain why do you believe so? The problem as you define it is a composition of functions, not a joint distribution. – llrs Oct 2 '18 at 15:38
• Because my lecturer wants it done that way. But it's a good question you pose because I was thinking this earlier today, can't it just be done similar to what you suggest? And then, what the hell do we need Bayesian statistics for? I but I'm too ignorant at this stage to answer these questions....except that this question is supposed to be interrogating our knowledge of simple bayesian techniques, hence the analytical priors. Thanks @Llopis. – Bucephalus Oct 2 '18 at 15:42
• it's 1:45am here, I'm going to bed. As @whuber indicated, I probably have not given enough information to answer this satisfactorily. I will close the question tomorrow if you wish. – Bucephalus Oct 2 '18 at 15:44
• I have got the assignment solution so yes I have. However the question wasn't exactly the same in the assignment, I simulated the question here when I asked it. So, once I go over it I will let you know. – Bucephalus Jan 2 at 15:51