# An exercise in bayesian statistics

Can you give me some suggestion on how to solve this?

Let $X_1, ... X_{20} |\theta \stackrel{iid}{\sim} Bern(\theta)$ and suppose $\theta \stackrel{}{\sim} Beta(2,2)$, namely:

$P[X_i = x | \theta] = \theta^x(1-\theta)^{1-x} \mathbb{1}_{0,1} (x)$ , and $g(\theta) = 6\theta(1-\theta)\mathbb{1}_{[0,1]}(\theta)$

(a) identify the posterior distribution of $\theta$, given $X_1=x_1, ... X_{20} = x_{20}$

What I did:
$f_{\theta | x}(\theta | x) = \frac{6\theta(1-\theta)}{\theta^{\sum_{i=1}^{n}x_{i}}(1 - {\theta)^{n-\sum_{i=1}^{n}x_{i}}} 6\theta(1-\theta)}$ Is this wrong? What is the range?

(b) determine the predictive distribution of $X_{21}$, given the observed sample, namely $P[X_{21} = 1 | x_1,...x_{20}]$

What I did:
$f_{x}(x) = \theta^{\sum_{i=1}^{n}x_{i}}(1 - {\theta)^{n-\sum_{i=1}^{n}x_{i}}6\theta(1-\theta)}$

(c) If the observed sample is such that $s_{20} = \sum_{i=1}^{20} x_i = 10$, determine $P[\theta < 0.5 | x_1,...x_{20}]$

What I did:
Should I compute the integral or the sum of $f_{x}(x)$? Or something totally different?

If the individual tries $X_i$ are Bernoulli distributed, then their sum $k:=\sum_{i=1}^{20} X_i$ is binomially distributed and the probability density function is $$f(k|\theta,n) = \binom{n}{k}\theta^k(1-\theta)^{n-k}$$ where the number of Bernoulli tries $n=20$ in your case.
What we are looking for is $$f(\theta|k,n) = \frac{f(k|\theta,n)f(\theta)}{f(k|n)}$$ We also know $f(\theta)$ which is given by the beta distribution. Lets look at the nominator to decide what $f(k|n)$ needs to be so that $f(k|\theta,n)$ integrates to one: \begin{align} f(k|\theta,n)f(\theta) &= \binom{n}{k}\theta^k(1-\theta)^{n-k} \cdot \frac{1}{B(a,b)}\theta^{a-1}(1-\theta)^{b-1}\\ &=\binom{n}{k}\frac{1}{B(a,b)} \theta^{k+a-1} (1-\theta)^{n-k + b -1} \end{align} This is almost the Beta distribution $Beta(a+k,b+n-k)$ and only differs by a constant factor. Since the pdf of the Beta distribution integrates to $1$ we know this constant factor musst be $f(k|n)$. Hence, to answer (a), the posterior distribution of $\theta$ is $$Beta\left(2+\sum_{i=1}^{20}X_i, 2 + 20 - \sum_{i=1}^{20}X_i\right).$$ In order to answer (b) I assume by "predictive distribution" you mean the probability that $X_{21}=1.$ In general we need to integrate the statistic we are looking for time its pdf given by $Beta$: $$\mathbb E[\theta] = \int_0^1\theta \cdot f(\theta) \mathrm d \theta.$$ This is just the expected value of the distribution and known for the beta distribution: $$\mathbb E[\theta] = \frac{2+\sum_{i=1}^{20}X_i}{2+2+20}$$ Now (c) is just the value of the cumulative beta distribution at $0.5$ with $\alpha = 12$ and $\beta = 12$: $$\int_0^{0.5} f_{Beta}(\theta|12,12) \mathrm d \theta = 0.5$$