# What does "Conditioning on the margins of ____" mean?

What does it mean to "condition on the margin of ____"? I lack statistical/mathematical training and phrases like these leave me bewildered and unsure where to look.

In this post (Which are differences between the hypergeometric distribution and chi-square distribution), there is an example where @Glen_b uses the phrase:

That is, your example data are like so:

            Drawn    Not drawn    Total

Red      160        6520        6680
Black    222       11938       12160

Total    382       18458       18840


Looking at the number of reds drawn as a random variable, that has a hypergeometric distribution (though there formulated in terms of white and black balls drawn from an urn rather than red and black balls drawn from a universe).

[Conditioning on the margins gives the hypergeometric - this is also the situation used for Fisher's exact test based on the hypergeometric, and one of the situations for which the usual 2x2 chi-square test of association/test of independence applies. If you don't condition on both margins, you don't have a hypergeometric; but that's what you normally do in the specific balls-in-urns model you describe.]

### Margins

Margins here refers to the values on the edges (margins!) of the table, that is, the total number of reds, total number of blacks, total number of drawn, and total number of not drawn. The related term marginal distribution refers to the distribution of a single variable obtained from a joint distribution of several variables by averaging over the other variables (etymologically, the term indeed comes from the values written on the margins of tables).

### Conditioning

Conditioning refers to computing conditional distributions, that is, probability distributions given some information. Here, conditioning on the margins means that the margins are fixed, i.e., we assume that there are in total 6680 red balls (and 12160 black balls), as well as 382 drawn balls (and 18458 balls not drawn). So that, for example

       Drawn  Not drawn  Total
Red      200       6480   6680
Black    182      11978  12160
Total    382      18458  18840


would be a possible realization of our random distribution (the margins are the same). Under the null hypothesis that getting drawn and the color of the ball are independent, conditioning on the margins leads to the hypergeometric distribution.

Alternatively, if the experiment were such that one draws balls until 160 reds are obtained, it would not make sense to condition on the margins (as the total number of drawn balls could have turned out something else than 382). In this case, one could obtain realizations like

       Drawn  Not drawn  Total
Red      160       6520   6680
Black    182      11978  12160
Total    342      18498  18840


which would have different margins.