The maximum likelihood estimate of a hierarchical log-linear model is the unique table in the model whose margins on the generators equal the observed margins. Iterative proportional fitting finds it by starting from the uniform table and rescaling it so that one generator margin is right, then the next, and so on in cycles. Each adjustment raises the log-likelihood and keeps the table inside the model. Step through it, change the model, start from a table outside the model, or put zeros in the data.
One adjustment for generator C: m(x) ← m(x) nC(xC) / mC(xC), where nC and mC are the observed and fitted C-margins. ℓ = Σ n(x) log(m(x)/n) is the multinomial log-likelihood; ℓ̂ is its maximum over the model (for the zeros table, the limit of the iterations). The random start multiplies each cell by 0.5 + 1.5u with u from the seeded generator (seed 19).
code/ch19_log_linear_models.py (ipf, closed_form, fit_model, coris_table; Figure 19.S1).