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.
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}$.