  Shortly after a new class of objects is discovered, the attention shifts from
the properties of the individual sources to the question of their origin: do
all sources come from the same underlying population, or several populations
are required? What are the properties of these populations? As the detection of
gravitational waves is becoming routine and the size of the event catalog
increases, finer and finer details of the astrophysical distribution of compact
binaries are now within our grasp. This Chapter presents a pedagogical
introduction to the main statistical tool required for these analyses:
hierarchical Bayesian inference in the presence of selection effects. All key
equations are obtained from first principles, followed by two examples of
increasing complexity. Although many remarks made in this Chapter refer to
gravitational-wave astronomy, the write-up is generic enough to be useful to
researchers and graduate students from other fields.
