How it’s calculated
A contingency (two-way) table counts how often each combination of two categorical variables occurs. Dividing by the right total turns the counts into probabilities:
- Joint probability P(A and B): the cell count ÷ the grand total.
- Marginal probability P(A): the row (or column) total ÷ the grand total.
- Conditional probability P(B | A): the cell count ÷ the row total of A. Knowing A shrinks the sample space to that row.
Worked example (OpenStax Introductory Statistics 2e, Example 3.20): of 755 drivers, 25 cell-phone users and 45 non-users had a speeding violation, while 280 users and 405 non-users had none. P(user) = 305/755 = 0.4040. P(user and no violation) = 280/755 = 0.3709. P(user or no violation) = (305 + 685 − 280)/755 = 710/755 = 0.9404. P(user | violation) = 25/70 = 0.3571, and P(no violation | not a user) = 405/450 = 0.9. Pick the row and column numbers to choose which events A and B the first results describe; the three tables at the end show every joint and conditional probability at once.
To test whether the two variables are related using a whole sample, use a chi-square test of independence; this page describes the probabilities in the table itself.
Frequently asked questions
What is the difference between joint and conditional probability?
Joint probability P(A and B) divides a cell by the grand total. Conditional probability P(B | A) divides the same cell by the total of the row (or column) you are conditioning on, because you already know A happened.
Why is P(A | B) different from P(B | A)?
They divide the same cell count by different totals: P(A | B) by the column total of B and P(B | A) by the row total of A. In the driver example P(user | violation) = 25/70 but P(violation | user) = 25/305.
Should I include the totals in the table?
No. Enter only the inner counts; the calculator adds up the rows, columns and grand total itself.
Does “not independent” mean the result is significant?
No. With sample data, P(A and B) will almost never exactly equal P(A)·P(B). To decide whether the difference is more than chance, run a chi-square test of independence on the same table.
Embed this calculator
Add this free calculator to your own website. Copy the code below into your page’s HTML:
Need this calculator branded, changed or built around your own prices?See custom business solutions →
Sources
Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.
Added · Last updated · How we check our calculators
Spotted a mistake or missing option? Report a problem· Suggest a calculator