# Bayesian – Posterior for Discrete Prior from Normal Sample with Known Variance

bayesianposteriorr

Given a sample $$(1,2,5,2.5,3,7)$$, and known $$\sigma^2 = 4$$ with possible values for prior mean of $$(0,0.5,1,1.5)$$ all equally likely, find the posterior distribution and the posterior probability that $$\mu\leq 1$$

So in R I have:

> sample = c(1,2,5,2.5,3,7)
> m = c(0,0.5,1,1.5)
> prior = (rep(1/4,4))
> lilklihood = dnorm(mean(sample), mean = m, sd = 2/sqrt(length(sample)))
> posterior = prior*liklihood/sum(prior*liklihood)
> posterior
[1] 0.002021756 0.021735920 0.160607934 0.815634390

So my posterior distribution just is this vector correct? The thing I find is that all my values are actually less than 1, so is posterior probability that $$\mu\leq 1$$ just 1?

The resulting posterior is the posterior probability associated with four possible values for the mean; therefore; \begin{aligned} &P(\mu = 0 \vert \textrm{data}) &&= 0.002021756,\\ &P(\mu = 0.5 \vert \textrm{data}) &&= 0.021735920,\\ &P(\mu = 1 \vert \textrm{data}) &&= 0.160607934,\\ &P(\mu = 1.5 \vert \textrm{data}) &&= 0.815634390,\\ \end{aligned} therefore $$P(\mu \leq 1 \vert \textrm{data})$$ is given by \begin{aligned} P(\mu \leq 1 \vert \textrm{data}) &= P(\mu = 0 \vert \textrm{data}) + P(\mu = 0.5 \vert \textrm{data}) + P(\mu = 1 \vert \textrm{data})\\ &= 0.18436561\\ &\approx 18\%. \end{aligned}