<s>[INST] Find the distribution of $X|Y =k$ given the distribution of $Y|X =x$ Good night, I'm trying to find the p.d.f of $Y$ and $X|Y=k$, and $\mathbb E (X|Y=k)$ in the following exercise:



Could you please verify if my attempt is correct or contains logical mistakes? Thank you so much for your help!

My attempt:
First, we have $$\begin{aligned} & \int_0^1 {n \choose k}  x^k (1-x)^{n-k}  \, \mathrm{d}x &&= {n \choose k} \int_0^1  x^{(k+1)-1} (1-x)^{(n-k+1)-1}  \, \mathrm{d}x \\ &= {n \choose k} B(k+1,n-k+1) &&= \frac{n!}{(n-k)!k!} \frac{k!(n-k)!}{(n+1)!} \\ &= \frac{1}{n+1} \end{aligned}$$ and $$\begin{aligned} & \int_0^1 {n \choose k} x^{k+1} (1-x)^{n-k}  \, \mathrm{d}x &&= {n \choose k} \int_0^1  x^{(k+2)-1} (1-x)^{(n-k+1)-1}  \, \mathrm{d}x \\ &= {n \choose k} B(k+2,n-k+1) &&= \frac{n!}{(n-k)!k!} \frac{(k+1)!(n-k)!}{(n+2)!} \\ &= \frac{k+1}{(n+2)(n+1)} \end{aligned}$$
We have $X \sim \mathcal U([0,1])$ and $(Y|X=x) \sim \mathcal B(n,x)$. Then $f_{Y|X} (k|x) = {n \choose k} x^k (1-x)^{n-k}$ and so $$\begin{aligned} f_Y (k) &= \int_{\mathbb R} f_{Y|X} (k|x) f_X (x) \, \mathrm{d}x  &&= \int_{\mathbb R} {n \choose k} x^k (1-x)^{n-k} \frac{1}{1-0} \textbf{1}_{[0,1]} (x) \, \mathrm{d}x \\&= \int_0^1 {n \choose k} x^k (1-x)^{n-k}  \, \mathrm{d}x  &&=  \frac{1}{n+1} \end{aligned}$$
As such, $Y$ is uniformly distributed discrete random variable with $\operatorname{supp} (Y)= \{0,\ldots,n\}$.
We have $$\begin{aligned} f_{X|Y} (x,k) &= \frac{f_{Y|X} (k|x) f_X(x)}{f_Y (k)} \\ &= \frac{{n \choose k} x^k (1-x)^{n-k} \frac{1}{1-0} \textbf{1}_{[0,1]} (x)}{\frac{1}{n+1}}\\ &= (n+1) {n \choose k} x^k (1-x)^{n-k} \textbf{1}_{[0,1]} (x) \end{aligned}$$
As such, $$\begin{aligned} \mathbb E (X|Y=k) &= \int_\mathbb R x f_{X|Y} (x,k)  \, \mathrm{d}x \\ &= \int_\mathbb R x (n+1) {n \choose k} x^k (1-x)^{n-k} \textbf{1}_{[0,1]} (x)  \, \mathrm{d}x \\ &= (n+1)  \int_0^1 {n \choose k} x^{k+1} (1-x)^{n-k} \, \mathrm{d}x \\ &= (n+1) \frac{k+1}{(n+2)(n+1)} = \frac{k+1}{n+2}\end{aligned}$$
 [/INST] I post my attempt in case $X \sim \operatorname{Beta}(a,b)$ here and is going to mark this answer as accepted to peacefully close this question.
Thank you again for your verification @Math1000 ^o^

We have $X \sim \operatorname{Beta}(a,b)$ and $(Y|X=x) \sim \mathcal B(n,x)$. Then $f_{Y|X} (k|x) = {n \choose k} x^k (1-x)^{n-k}$ and thus $$\begin{aligned} f_Y (k) &= \int_{\mathbb R} f_{Y|X} (k|x) f_X (x) \, \mathrm{d}x  \\&= \int_{\mathbb R} {n \choose k} x^k (1-x)^{n-k} \frac{x^{a-1}(1-x)^{b-1}}{\mathrm{B}(a, b)} \textbf{1}_{[0,1]} (x) \, \mathrm{d}x \\&= {n \choose k} \frac{1}{\mathrm{B}(a, b)} \int_0^1 x^{(k+a)-1} (1-x)^{(n-k+b)-1}   \, \mathrm{d}x  \\&=  {n \choose k}  \frac{\mathrm{B}(k+a,n-k+ b)}{\mathrm{B}(a, b)} \end{aligned}$$
We have $$\begin{aligned} f_{X|Y} (x,k) &= \frac{f_{Y|X} (k|x) f_X(x)}{f_Y (k)} \\ &= \frac{{n \choose k} x^k (1-x)^{n-k} \frac{x^{a-1}(1-x)^{b-1}}{\mathrm{B}(a, b)} \textbf{1}_{[0,1]} (x)}{ {n \choose k}  \frac{\mathrm{B}(k+a,n-k+ b)}{\mathrm{B}(a, b)}}\\ &= \frac{x^{k+a-1} (1-x)^{n-k+b-1}}{\mathrm{B}(k+a,n-k+ b)} \textbf{1}_{[0,1]} (x) \end{aligned}$$
As such, $(X|Y=k) \sim \operatorname{Beta}(k+a,n-k+b)$. Hence $\mathbb E(X|Y=k) = \frac{k+a}{n+a+b}$.
</s>