# Posterior for Discrete prior from normal sample with known variance

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?

• It is not clear what you mean. You mention Dirichlet distribution in the title, but use Gaussians in the code, those two are completely unrelated. It is not clear what are you trying to do.
– Tim
Mar 14, 2022 at 13:08
• @Tim, I think you have misread "Discrete" as "Dirichlet". Mar 14, 2022 at 14:30
• @PeterPang please do not make edits that change the meanings of questions or answers by others. Edits are meant for things like typos, fixing broken links, formatting, etc, not for re-wording the content.
– Tim
Mar 14, 2022 at 14:33
• @Tim, I thought the question was closed because it was not detailed enough and therefore asking for people to edit and add details. Mar 14, 2022 at 14:36
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}