Mixture allocation indicator (source code)

= Mixture allocation indicator
{title2=$I_j=\mathbf1_{\{Z=j\}}$}

Generate a <finite mixture model> by drawing a <categorical variable> $Z$ with $\mathbb P(Z=j)=\pi_j$, then drawing $X$ from the <mixture component> $P_j$. The <indicator random variables> $I_j=\mathbf1_{\{Z=j\}}$ satisfy $\sum_jI_j=1$: exactly one <mixture component> generates each draw. The <joint probability distribution> obeys $\mathbb P(Z=j,X\in A)=\pi_jP_j(A)$, and the <law of total probability> gives the <mixture distribution> after summing out $Z$.<Advanced Data Analysis from an Elementary Point of View, 2015 draft by Cosma Rohilla Shalizi/Mixture Models>[§21.1.3, printed p. 443, equations (21.2)-(21.3), and §21.1.7, p. 446: choose a label, then sample its component]{ref}

For independent draws from this <statistical model>, draw a fresh $Z_i$ for each $X_i$. Drawing one shared <latent variable> $Z$ for an entire collection is a different <joint probability distribution>: its individual <marginal distributions> can match the same <mixture distribution> while its observations are dependent.