Joint vs Marginal vs Conditional Probability with Example Python code

To drive the point home, lets straightway get started with the below hypothetical dataset of smoker data across three Indian cities:

First, let’s convert it to a contingency table:

Citynon-smokersmokertotal
delhi6511
kolkata369
mumbai7714
total161834

Now, Joint probability of delhi AND non-smoker  = P(delhinon-smoker) = 6/34= 0.18

Similarly, for all the other combinations joint probabilities can be calculated as:

Citynon-smokersmokertotal
delhi0.180.150.32
kolkata0.090.180.26
mumbai0.210.210.41
total0.470.531.0

Marginal probabilities are the probabilities lies in the margin of the above table. and the meaning is , the marginal probability of person randomly selected will be from delhi is 0.32 .

Conditional probability that a randomly selected non-smoker person is from delhi =

P(delhi | non-smoker) = 6/16=0.38

Similarly, for the other combinations the conditional probabilities could be calculated as:

indexCitynon-smokersmoker
0delhi0.380.28
1kolkata0.190.34
2mumbai0.450.4

The concept of conditional /marginal / joint probability is important to test dependency of the variables, how? lets keep it for some other day.

Shibashis

Hi, I am Shibashis, a blogger by passion and an engineer by profession. I have written most of the articles for mechGuru.com. For more than a decades i am closely associated with the engineering design/manufacturing simulation technologies. I am a self taught code hobbyist, presently in love with Python (Open CV / ML / Data Science /AWS -3000+ lines, 400+ hrs. )

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.