Cross Validated Asked by anonymous on October 2, 2020

I have a two-class problem. Let’s call the first class W1 and the second W2. I am trying to find the posterior distributions of both W1 and W2. I know I can use the following formula to do so…

$$

P(W_j|X) = frac{P(X|W_j)P(W_j)}{P(X)}

$$

where

$$

P(X) = sum_{i=1}^{2}P(X|W_i)P(W_i)

$$

So if I was trying to find the posterior distribution of W1, I would do the following

$$

P(W_1|X) = frac{P(X|W_1)P(W_1)}{P(X|W_1)P(W_1)+P(X|W_2)P(W_2)}

$$

I know the denominator is supposed to be a constant… but looking at this formula I don’t understand how the denominator would become a constant. Aren’t $P(X|W_1)P(W_1)$ and $P(X|W_2)P(W_2)$ both distributions. Would I have to sum all the values of both distributions together? Thanks for any help and I apologize if this is a silly question.

Code attempt is below:

```
P_w1_likelihood <- rnorm(n = 1000,mean = 4,sd = 2)
P_w1_prior <- 0.5
P_w2_likelihood <- rnorm(n = 1000,mean = 6,sd = 3)
P_w2_prior <- 0.5
P_w1_posterior <- P_w1_likelihood*P_w1_prior/(sum(P_w1_likelihood*P_w1_prior)+sum(P_w2_likelihood*P_w2_prior))
P_w2_posterior <- P_w2_likelihood*P_w2_prior/(sum(P_w1_likelihood*P_w1_prior)+sum(P_w2_likelihood*P_w2_prior))
Posteriors <- data.frame(
"Posterior" = c(P_w1_posterior,P_w2_posterior),
"Distribution" = c(rep("W1|X",times = 1000),rep("W2|X",times = 1000))
)
ggplot(Posteriors,aes(x = Posterior,group = Distribution,fill = Distribution))+
geom_histogram(alpha = 0.7)+
scale_fill_manual(values = c("orangered","darkorchid2"))
```

Get help from others!

Recent Questions

- How can I transform graph image into a tikzpicture LaTeX code?
- How Do I Get The Ifruit App Off Of Gta 5 / Grand Theft Auto 5
- Iv’e designed a space elevator using a series of lasers. do you know anybody i could submit the designs too that could manufacture the concept and put it to use
- Need help finding a book. Female OP protagonist, magic
- Why is the WWF pending games (“Your turn”) area replaced w/ a column of “Bonus & Reward”gift boxes?

Recent Answers

- Lex on Does Google Analytics track 404 page responses as valid page views?
- Joshua Engel on Why fry rice before boiling?
- haakon.io on Why fry rice before boiling?
- Peter Machado on Why fry rice before boiling?
- Jon Church on Why fry rice before boiling?

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP