# In a 2 class problem how do I compute the normalization constant for finding the posterior distributions?

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


## Related Questions

### Fixed effects versus random effects in panel data for intervention group only? Change in dependent variable for each time period

0  Asked on December 11, 2021 by isobel-m

### How to calculate ARIMA(1,0,0)(1,0,1)12 prediction by hand

1  Asked on December 10, 2021 by code_diy

### Compare RMSE for the same model but varying sample size

3  Asked on December 8, 2021 by skoestlmeier

### ANOVA determining percentage of variation

2  Asked on December 8, 2021 by unistudent87

### Oscillating validation accuracy for a convolutional neural network?

3  Asked on December 8, 2021 by rockthestar

### Beta values for mixed models

1  Asked on December 8, 2021

### Comparing top level group effects using a 3-level hierarchical regression

1  Asked on December 8, 2021 by kev8484

### What are the worst (commonly adopted) ideas/principles in statistics?

32  Asked on December 8, 2021

### Statistical Analysis over different samples – Prediction for the number of objects

0  Asked on December 8, 2021

### Group level distribution for positive parameters in Bayesian multilevel models

0  Asked on December 8, 2021 by likao

### Learning more about glm parameters, how to dig deeper?

0  Asked on December 8, 2021

### OLS regression interpretation when sample means from t-test are insignificant

0  Asked on December 8, 2021 by thetagang

### Can we compare the effects of continuous covariate and categorical covariate on response variable in generalized linear regression?

0  Asked on December 8, 2021

### what is Multivariate Data

2  Asked on December 8, 2021

### Why LIME does not show the attribution for each features

0  Asked on December 8, 2021

### Is it useful or even necessary to standardize independent variables for linear regression?

1  Asked on December 8, 2021

### Why and under what conditions does Q learning converge?

0  Asked on December 8, 2021

### How to factor this conditional probability?

1  Asked on December 8, 2021 by user292136

### What are some good resources to learn Statistical Genetics?

1  Asked on December 6, 2021 by hulk