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"))
```

0 Asked on December 11, 2021 by isobel-m

1 Asked on December 10, 2021 by code_diy

3 Asked on December 8, 2021 by skoestlmeier

2 Asked on December 8, 2021 by unistudent87

3 Asked on December 8, 2021 by rockthestar

1 Asked on December 8, 2021

1 Asked on December 8, 2021 by kev8484

32 Asked on December 8, 2021

0 Asked on December 8, 2021

0 Asked on December 8, 2021 by likao

0 Asked on December 8, 2021

0 Asked on December 8, 2021 by thetagang

0 Asked on December 8, 2021

categorical data generalized linear model multiple regression regression

0 Asked on December 8, 2021

2 Asked on December 8, 2021 by sadisha

1 Asked on December 8, 2021

machine learning multiple regression regression standardization

0 Asked on December 8, 2021

machine learning neural networks q learning references reinforcement learning

1 Asked on December 8, 2021 by user292136

1 Asked on December 6, 2021 by hulk

Get help from others!

Recent Answers

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

Recent Questions

- 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?
- Does Google Analytics track 404 page responses as valid page views?

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir