Contingency Table Probability Calculator

Joint, marginal and conditional probabilities from a 2×2 to 4×4 table of counts, plus P(A or B) and an independence check.

One row per line, counts separated by spaces or commas, 2 to 4 rows and columns. Counts only, no totals. Use a point for decimals (1.5), no thousands separators, and separate numbers with spaces or a comma and a space.
Separated by commas, in order. Leave empty for Row 1, Row 2, …
Separated by commas, in order. Leave empty for Column 1, Column 2, …

Results

P(Uses phone and Violation)
0.033113
25 ÷ 755
P(Uses phone)
0.403974
row total 305 ÷ 755
P(Violation)
0.092715
column total 70 ÷ 755
P(Uses phone or Violation)
0.463576
(305 + 70 − 25) ÷ 755
P(Violation | Uses phone)
0.081967
25 ÷ 305
P(Uses phone | Violation)
0.357143
25 ÷ 70
Independence check
P(Uses phone) × P(Violation) = 0.0374545 ≠ P(Uses phone and Violation) = 0.0331126, so these two events are not independent.
Grand total
755
Joint probabilities (each cell ÷ grand total), with marginal totals
Violation No violation Total Uses phone 0.0331 0.3709 0.4040 No phone 0.0596 0.5364 0.5960 Total 0.0927 0.9073 1.0000
Conditional on the row: P(column | row)
Violation No violation Uses phone 0.0820 0.9180 No phone 0.1000 0.9000
Conditional on the column: P(row | column)
Violation No violation Uses phone 0.3571 0.4088 No phone 0.6429 0.5912

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:

P(A and B) = cell ÷ N P(A) = row total ÷ N, P(B) = column total ÷ N P(A or B) = P(A) + P(B) − P(A and B) P(B | A) = cell ÷ row total = P(A and B) ÷ P(A) A and B are independent when P(A and B) = P(A) × P(B)

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