Bayesian estimation I am a bit confused with this example.
Suppose that the number of defects on a roll of magnetic recording tape has a Poisson distribution for which the mean λ is known to be either 1 or 1.5. Suppose the prior mass function for λ is $π_λ(1)$ = 0.4, $π_λ(1.5)$ = 0.6 . 
A collection of 5 rolls of tape are found to have x = (3, 1, 4, 6, 2) defects respectively. 
Show that the posterior distribution for λ is 
$π_λ(1 | x)$ = 0.012, $π_λ (1.5 | x)$ = 0.988. 
 A: The posterior distribution of $\lambda$ given number of defects in 5 trials ($X_1,\ldots,X_5$) is:
\begin{align}
P(\lambda|X_1,\ldots,X_5) &= \frac{P(X_1,\ldots,X_5|\lambda) P(\lambda)}{P(X_1,\ldots,X_5)} \\
&= \frac{P(X_1,\ldots,X_5|\lambda) P(\lambda)}{\sum_{\lambda'}P(X_1,\ldots,X_5|\lambda')P(\lambda')} \\
&= \frac{P(\lambda)\prod_{i=1}^5P(X_i|\lambda)}{\sum_{\lambda'}P(\lambda')\prod_{i=1}^5P(X_i|\lambda')} \\
\end{align}
where the sum in the denominator is over $\lambda' = 1, 1.5$. I have also assumed that the $5$ trials are conditionally independent and identically distributed as Poisson with a $\lambda \in \{1,1.5\}$. You can now use the given priors and the Poisson distribution's probability mass function to find the above posterior for $\lambda \in \{1,1.5\}$.
A: You can do this in R:

la <- sum(log(dpois(c(3, 1, 4, 6, 2), 1)))
  lb <- sum(log(dpois(c(3, 1, 4, 6, 2), 1.5)))
  .4*exp(la) / (.4*exp(la) + .6*exp(lb))
  [1] 0.01221372
  .6*exp(lb) / (.4*exp(la) + .6*exp(lb))
  [1] 0.9877863

I don't know how to format that.
