# How to use bayes rule when B is a category

Lets say I have a probability of the number of goals in a game, given the league that the game is played in.

A = #Goals B = league

Using Bayes theorem: P(A|B) = P(B|A)P(A)/P(B)

Lets say B = 'Premier League'

How do you compute P(B|A) if B is a category? In my head P(B|A) means "Compute the probability of seeing B='Premier League' over every possible value of A".

Lets say A=2, I could look at the probability that A=2 in each league I have data for. Lets say that in the premier league it is 0.3, in Serie A it is 0.2, and in La Liga it is 0.4. I could then say P(B|A) = 0.3/(0.4+0.2+0.3) = 1/3.

Does that make sense? I have been trying to think how to do this for a few days and I cant get my head around B being categorical. If it was continuous P(B|A) would just be "What is the probability of seeing your observed value of B, for each possible value of A" I think.. Which makes more sense.

The way that I would think about it is the following:

First I would try to define the sample space of that problem, i.e the space that will contain all the possible results. In order to define that I would consider what values the events $$A$$ and $$B$$ can take.

$$A$$ which is the number of goals can take the following value $$\left \{ 0,1,2,... \right \}$$, while $$B$$ the league has three possible categories $$\left \{ B_{1},B_{2},B_{3} \right \}$$.

Then I would define the sample space $$\Omega$$ as the collection of all possible combinations/results of values of $$A$$ with the values of $$B$$. So, $$\Omega$$ it will contain the event that you used $$(A=2)\cap B_{1}$$ and $$(A=2)\cap B_{2}$$ and $$(A=2)\cap B_{3}$$ and all such events that make sense for your problem.

Then for the conditional probability of $$B$$ given $$A$$ you will have the probability rule

$$\mathbb{P}(B|A) = \frac{\mathbb{P}(B\cap A)}{\mathbb{P}(A)}$$

however, in order to make inference you have to specify the events $$B\cap A$$ and $$A$$.

So you could write all the events that you are interested in $$B=B_{1}$$ with $$A=2$$ or $$B=B_{2}$$ with $$A=2$$ etc.

And this will be transalated in probability as

$$\mathbb{P}(B=B_{1}|A=2)=\frac{\mathbb{P}((B=B_{1})\cap (A=2))}{\mathbb{P}(A=2)}$$,

where the events $$(B=B_{1})\cap (A=2)$$ and $$(A=2)$$ belong into your sample space $$\Omega$$ so you can define probabilities on them.

So, overall if you approach the conditional probability as the probability of a particular event happening (i.e. a combination of $$A$$ and $$B$$ happening) then it would be easier to understand it.

• Thanks! Is P(A=2) in the denominator the probability of A being equal to 2 across all games (i.e. taken from a probability distribution of just A)? Commented May 10, 2021 at 8:03
• @ChristopherCollins Exactly! Which can be expressed as $\mathbb{P}(A=2) = \mathbb{P}(A=2|B=B_{1})\mathbb{P}(B=B_{1})+\mathbb{P}(A=2|B=B_{2})\mathbb{P}(B=B_{2})+\mathbb{P}(A=2|B=B_{3})\mathbb{P}(B=B_{3})$ Commented May 10, 2021 at 8:21
• Amazing, thanks! This has really helped my understanding Commented May 10, 2021 at 16:03
• @ChristopherCollins Glad to hear that! Commented May 10, 2021 at 16:08