Joint probability of binomial RV with its number of successes $P(\textbf{Y}=\textbf{y},\sum Y_i=z)$ From the appendix of Bickel and Doksum: let $\textbf{Y}=(Y_1,...Y_n)$ where $Y_i$ indicator of $n$ Bernoulli trials with probability $p$.  Let $Z=\sum_{i=1}^nY_i$.  Then $Z$ has a binomial distribution and 
$$p(\textbf{y}|z)
=\dfrac{P(\textbf{Y}=\textbf{y},Z=z)}{{n \choose z}p^z(1-p)^{n-z}}
=\dfrac{p^z(1-p)^{n-z}}{{n \choose z}p^z(1-p)^{n-z}}$$
I am trying to understand this equality.
One option is: 
$P(\textbf{Y}=\textbf{y},Z=z)=P(\textbf{Y}=\textbf{y}|Z=z)P(Z=z)$, but we are trying to find an expression for $p(\textbf{y}|z)$, so this must not be the right path.
That leaves us only with: 
$P(\textbf{Y}=\textbf{y},Z=z)=P(Z=z|\textbf{Y}=\textbf{y})P(\textbf{Y}=\textbf{y})$ 
Then by independence 
$P(\textbf{Y}=\textbf{y})=P(Y_1=y_1,...,Y_n=y_n)=P(Y_1=y_1)\cdot ...\cdot P(Y_n=y_n)=p^z(1-p)^{n-z}$
What about $P(Z=z|\textbf{Y}=\textbf{y})$?  
Having observed, say, $\textbf{Y}=(1,0,1,1)$, $Z$ is fixed at 3.  So $P(Z=3|\textbf{Y}=(1,0,1,1))=1$.
Then $P(Z=z|\textbf{Y}=\textbf{y})=1$?
 A: First, let me rewrite your problem with notations that are helpful in understanding the above problem. Let $y_i \in \{0,1\}$, $i \in \{1,\ldots,n\}$ be a Bernoulli random variable that takes the value of either $0$ or $1$. Each random variable is drawn with a probability $p$. Therefore, the joint mass function can be written as as
\begin{align}
P(y_1,\ldots,y_n|p) =  P(\mathbf{y}|p) = p^{\sum_{i=1}^n y_i} (1-p)^{n-\sum_{k=1}^n y_i}
\end{align}
Let $z$ be a random variable such that $z = \sum_{i=1}^n y_i$. Then, the probability mass function of $z$ follows a binomial distribution and is given as
\begin{align}
P(z|p) = {n \choose z} p^{z} (1-p)^{n-z}.
\end{align}
Therefore, the joint probability mass function of $\mathbf{y}$ and $z$ is given as
\begin{align}
P(\mathbf{y},z|p) &= \begin{cases} P(\mathbf{y}|p) \quad \mbox{if} \quad z = \sum_{i=1}^n y_i \\ 0 \end{cases} \\
&= p^{z} (1-p)^{n-z} \mathcal{I}\left(z = \sum_{i=1}^n y_i\right)
\end{align}
where $\mathcal{I}(\cdot)$ is an indicator function that takes the value $1$, if the equality holds true. Therefore,
\begin{align}
P(\mathbf{y}|z,p) &= \frac{P(\mathbf{y},z|p)}{P(z|p)} \\
&=\frac{p^{z} (1-p)^{n-z} \mathcal{I}\left(z = \sum_{i=1}^n y_i\right)}{{n \choose z} p^{z} (1-p)^{n-z}} \\
&= \frac{1}{{n \choose z}}\mathcal{I}\left(z = \sum_{i=1}^n y_i\right).
\end{align}
Similarly,
\begin{align}
P(z|\mathbf{y},p) &= \frac{P(\mathbf{y},z|p)}{P(\mathbf{y}|p)} \\
&= \frac{p^{z} (1-p)^{n-z} \mathcal{I}\left(z = \sum_{i=1}^n y_i\right)}{ p^{z} (1-p)^{n-z}} \\
&= \mathcal{I}\left(z = \sum_{i=1}^n y_i\right).
\end{align}
A: Please note that 
the event $\textbf{Y}=(Y_1,...Y_n)$ is a subset of the event $Z=z$
Let's make an example
You have the event $\textbf{Y}=(1,1,0)$ that would make $Z = 2$.
But Z can be equal to 2 also with the event  $\textbf{Y}=(1,0,1)$.
Therefore the probability $P(\textbf{Y}=\textbf{y},Z=z)$ reduces to the probability of $P(\textbf{Y}=\textbf{y})$, but only if $\sum_{i=1}^nY_i = Z$, otherwise is equal to zero.
Let's make an example 
The joint probability of the events $\textbf{Y}=(1,1,0)$ and $Z=1$ is zero because $Z=\sum_{i=1}^nY_i$.
If $Y$ is an event such that $Z(Y) \neq z$ then clearly $P(\textbf{Y}=\textbf{y},Z=z) = 0$
That being said the formula you want to understand is explained because the numerator is equal to
$P(\textbf{Y}=\sum_{i=1}^nY_i)$
EDIT
Can you show why the last line is true?
my entire answer was meant to let you understand why the last line is true
Anyway the last line line is true because of the following 


*

*the numerator is $P(\textbf{Y}=\textbf{y},Z=z)$

*Substituting $Z=\sum_{i=1}^nY_i$ into the formula above we get $P(\textbf{Y}=\textbf{y},Z=z) = P(\textbf{Y}=\textbf{y},\sum_{i=1}^nY_i=z)$

*If $Y$ is an event such that $Z(Y) \neq z$ then clearly $P(\textbf{Y}=\textbf{y},Z=z) = 0$

*Otherwise $P(\textbf{Y}=\textbf{y},Z=z) = P(\textbf{Y}=\textbf{y},\sum_{i=1}^nY_i=z) = P(\textbf{Y}=\textbf{y})$ being the event $\textbf{Y}=\textbf{y}$ a subset of the event $Z=z$

*$P(\textbf{Y}=\textbf{y}) = p^{\sum_{i=1}^n y_i} (1-p)^{n-\sum_{k=1}^n y_i} =p^{z} (1-p)^{n-z}$  
