How can the negative binomial distribution be derived from another more "elementary" distribution? I am looking at the negative binomial distribution for the case where $p$ corresponds to "success probability" and $r$ is the integer number of "failures".  In this case we have $$E(X)=\frac{rp}{1−p}$$  $$\text{Var}(X)=\frac{rp}{(1−p)^2}$$
I thought it might be derived from the geometric distribution but the geometric distribution is derived from the negative binomial distribution, and not the other way round? 
Please explain and a source that I can use would also be great for this. 
 A: You look at a sequence of independent Bernoulli trials $\{B_i\}$ where $B_i\sim Bernoulli(1-p)$. So $B_i=1$ denotes success and $B_i=0$ denotes failure.
Let $N$ be the number of successes needed to get the first failure. So if $N=k$, ($k\geq0$) then you have $k$ successes before you get the first failure at $(k+1)$-th trial. In other words, if $N=k$ then you get to observe $(B_1=1,B_2=1,...,B_k=1,B_{k+1}=0)$. Then $N\sim Geometric(p)$.
Now let $N_r$ be the number of Bernoulli successes you observe before getting the $r$-th failure. Then you can see that you have to observe a random number of successes before getting the first failure, then a random number of successes before getting the second failure, and so on, till a random number of successes before getting the $r$-th failure. Each such random number of successes has $Geometric(p)$ distribution. So $N_r$ is the sum of $r$ many $Geometric(p)$ random variables. This $N_r$ has the $Negative$ $Binomial$ distribution.
So it is the other way round: the Geometric distribution gives rise to the Negative Binomial distribution.
Expectation of the Negative Binomial distribution is just the sum of expectations of $r$ many Geometric($p$) random variables. Each has expectation $\dfrac{p}{1-p}$, so our Negative Binomial has expectation $\dfrac{rp}{1-p}$.
Since the Geometric random variables are independent, variance of Negative Binomial is sum of variances of $r$ many Geometric($p$) random variables. A $Geometric(p)$ r.v. has variance $\dfrac{p}{(1-p)^2}$, so our Negative Binomial has variance $\dfrac{rp}{(1-p)^2}$.
A: The (0 based) geometric distribution is that of the count of failures before the first success in an indefinite sequence of independent Bernoulli trials with identical success rate.
A negative binomial distribution is that of the count of successes before a specified number of failures occurs in an indefinite sequence of independent  Bernoulli trials with identical success rate.
These definitions are clearly inter related.   You can derive one from the other, or both together from first principles.  
It all depends on what seed you have been given.  

Let $X_i$ be a geometric random variable with success rate, $1-p$.   Then by applying the above definition it is apparent that $X_i$ has a negative binomial distribution the count of 'successes' before 1 'failure', with 'failure' rate $1-p$.
$$X_i\sim\mathcal {Geo_0}(1-p) \iff X_i~\sim~\mathcal{NegBin}(1, p)$$
So if you are given the probability mass function, expectation, and variance, for a general negative binomial, you can immediately find the probability mass function, expectation, and variance for a geometric random variable.

Let $Y_r$ be a negative binomial random variable with success rate, $p$, and specified number of successes $r$.   Then $Y_r$ is the sum of $r$ independent geometric distributions with identical success rate $1-p$.   (Can you see why?)
$$Y_r\sim\mathcal{NegBin}(r, p)~\iff~ Y_r=\sum_{i=1}^r X_i~\wedge~ {\bigl(X_i\bigr)}_{i=1}^r\overset{\rm iid}\sim\mathcal{Geo_0}(1-p)$$
So if you have been given the pmf for a geometric distribution, you can obtain the general pmf, expectation, and variance, of a negative binomial distribution, with just a little work. 

So if you start with $\mathsf E(X_1)=p(1-p)^{-1}, \mathsf {Var}(X_1)=p(1-p)^{-2}$ because, $X_1\sim\mathcal{Geo_0}(1-p)$ then... 

 $$\begin{align}\mathsf E(Y_r) ~&=~ \sum_{i=1}^r\mathsf E(X_i) \\[1ex] &=~ r\mathsf E(X_1) \\[1ex] ~&=~ rp(1-p)^{-1}\\[2ex]\mathsf {Var}(Y_r) ~&=~ \sum_{i=1}^r\mathsf {Var}(X_i)+2\sum_{1\leq i<j\leq r}\mathsf{Cov}(X_i,X_j)\\[1ex] &=~ r\mathsf{Var}(X_1) \\[1ex] &=~ rp(1-p)^{-2}\end{align}$$ 

