liveBook · Manning

Complement

As explained in Statistics Every Programmer Needs

A complement event is the set of outcomes in a probability space that are not contained in the specified event.

A complement event contains every outcome excluded from an event A. Its probability is P(Aᶜ) = 1 − P(A), making it useful when the inverse event is easier to calculate. section 3.2.1

Use the complement rule to simplify probability calculations:

  • Identify the desired event and its complement. section 3.2.1
  • Calculate the complement, often with the multiplication rule for repeated independent outcomes. section 3.2.1
  • Subtract the complement probability from 1 to obtain the desired probability. section 3.2.1 section 3.2.3

At least one four in two dice rolls

Instead of adding the cases containing one or two fours, calculate the complement: neither die shows a four, with probability (5/6)² = 25/36. Therefore, P(at least one four) = 1 − 25/36 = 11/36, or about 31%. A short calculation gives the complement probability as approximately 69.44%. section 3.2.1

>>> probability_not_4_both = pow(probability_not_4, 2)

Computes the probability that neither of two dice shows a four by squaring the single-roll complement probability. section 3.2.1

How Statistics Every Programmer Needs covers it

How deep it goes
Explains the formula, repeated-outcome calculation, dice examples, and a short computational listing without developing formal proofs.
Examples
Uses two dice, sums of 12, and repeated coin flips to demonstrate complementary and direct probability calculations.
What it assumes
Assumes basic probability, sample spaces, and multiplication and addition rules while defining complements directly.
What you can do after
Apply it to replace cumbersome event counting with complement calculation and basic arithmetic.
How it connects
Links complements with the multiplication rule, addition rule, conditional probability, and probability distributions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.