How to find the distribution of the result of a compound experiment I'm trying to find the distribution of data collected from a die-roll and coin-toss experiment. The experiment is as follows:
1)Roll a fair die so that you get a number $D \in (1,...,6)$ 
2)Flip a fair coin $D$ number of times (i.e. the value on the dice) and record the number of tails $T$
Repeat this experiment for 10000 runs and define the random variable $W$ as the number of runs needed until an outcome of $T \geq 5$ occurs for the first time. 
Am I right in thinking that $T$ would be geometrically or negative binomially distributed? Just a note, I'm doing all my modelling and simulations in R.
 A: Everything depends on the chance of observing five or more tails ($T\ge 5$).  This can happen in two disjoint ways:


*

*The die shows $5$ (chance is $1/6$) and all five coin flips are tails (chance is $1/2^5=1/32$).

*The die shows $6$ (chance is $1/6$) and five of the six coin flips are tails (chance is $\binom{6}{5}(1/2)^6 = 6/64 = 3/32$.
The total chance is $1/6 \times 1/32 + 1/6 \times 3/32 = 1/6 \times 4/32 = 1/48$.
We have reduced the question to this (or at least I interpret it as such), which clearly you know how to answer:

An event of interest in an experiment (namely that $T \ge 5$) occurs with probability $1/48$.  The experiment is repeated until this event first occurs.  The number of repetitions needed is recorded as $W$.  What is the distribution of $W$?

By stating the question somewhat abstractly--including only the relevant information--it should now be clear that how the experiment is performed is of no consequence and all that matters are two things: (1) that successive runs of the experiment are independent and (2) the probability of the event of interest.
Notice that when attention focuses on $W$, we do not need to know precisely how $T$ is distributed.

It is amusing and instructive--although computationally inefficient--to study a simulation built according to the precise instructions of the experiment.  I will cheat a little, though: it usually is not needed to run the experiment $10000$ times to compute $W$.  $1000$ times will more than suffice.  This simulation in R repeats the entire process $10^4$ times.
experiment <- function(n, d=6, p=1/2, t=5) {
  # Returns NA when event `coin >= t` is never observed.  Beware!
  die <- ceiling(runif(n, 0, d)) # Roll a fair die with `d` faces
  coin <- rbinom(n, die, p)      # Flip a coin as many times as shown on the die
  T <- coin >= t                 # Identify when `t` is reached or exceeded
  match(1, T)                    # Count the number of tries needed
}

set.seed(17)
hist(results <- replicate(10^4, experiment(10^3)), probability=TRUE, breaks=40)
lines(dgeom(1:max(results, na.rm=TRUE), 1/48), col="Red", lwd=2) # Is this correct?

The code is written to let the die, the tail probability ($1/2$), and the threshold ($5$) easily be varied so that we can study how they influence the results and verify any more general formulas we might care to derive.

The red curve plots the PDF of a geometric distribution with parameter $1/48$ for comparison.
