Neha Patil (Editor)

Iterative proportional fitting

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

The iterative proportional fitting procedure (IPFP, also known as biproportional fitting in statistics, RAS algorithm in economics and matrix raking or matrix scaling in computer science) is an iterative algorithm for estimating cell values of a contingency table such that the marginal totals remain fixed and the estimated table decomposes into an outer product.

Contents

IPF is a method that has been "re-invented" many times, e.g. G.U. Yule in 1912 in relation to standardizing cross-tabulations and Kruithof in 1937 in relation to telephone traffic ("Kruithof’s double factor method") , and expanded upon by Deming and Stephan in 1940 (they proposed IPFP as an algorithm leading to a minimizer of the Pearson X-squared statistic, which it does not, and even failed to prove convergence), it has seen various extensions and related research. A rigorous proof of convergence by means of differential geometry is due to Fienberg (1970). He interpreted the family of contingency tables of constant crossproduct ratios as a particular (IJ − 1)-dimensional manifold of constant interaction and showed that the IPFP is a fixed-point iteration on that manifold. Nevertheless, he assumed strictly positive observations. Generalization to tables with zero entries is still considered a hard and only partly solved problem.

An exhaustive treatment of the algorithm and its mathematical foundations can be found in the book of Bishop et al. (1975). The first general proof of convergence, built on non-trivial measure theoretic theorems and entropy minimization, is due to Csiszár (1975). Relatively new results on convergence and error behavior have been published by Pukelsheim and Simeone (2009) . They proved simple necessary and sufficient conditions for the convergence of the IPFP for arbitrary two-way tables (i.e. tables with zero entries) by analysing an L 1 -error function.

Other general algorithms can be modified to yield the same limit as the IPFP, for instance the Newton–Raphson method and the EM algorithm. In most cases, IPFP is preferred due to its computational speed, numerical stability and algebraic simplicity.

Algorithm 1 (classical IPFP)

Given a two-way (I × J)-table of counts ( x i j ) , where the cell values are assumed to be Poisson or multinomially distributed, we wish to estimate a decomposition m ^ i j = a i b j for all i and j such that ( m ^ i j ) is the maximum likelihood estimate (MLE) of the expected values ( m i j ) leaving the marginals x i + = j x i j and x + j = i x i j fixed. The assumption that the table factorizes in such a manner is known as the model of independence (I-model). Written in terms of a log-linear model, we can write this assumption as log   m i j = u + v i + w j + z i j , where m i j := E ( x i j ) , i v i = j w j = 0 and the interaction term vanishes, that is z i j = 0 for all i and j.

Choose initial values m ^ i j ( 0 ) := 1 (different choices of initial values may lead to changes in convergence behavior), and for η 1 set

m ^ i j ( 2 η 1 ) = m ^ i j ( 2 η 2 ) x i + k = 1 J m ^ i k ( 2 η 2 ) m ^ i j ( 2 η ) = m ^ i j ( 2 η 1 ) x + j k = 1 I m ^ k j ( 2 η 1 ) .

Notes:

  • Convergence does not depend on the actual distribution. Distributional assumptions are necessary for inferring that the limit ( m ^ i j ) := lim η ( m ^ i j ( η ) ) is an MLE indeed.
  • IPFP can be manipulated to generate any positive marginals be replacing x i + by the desired row marginal u i (analogously for the column marginals).
  • IPFP can be extended to fit the model of quasi-independence (Q-model), where m i j = 0 is known a priori for ( i , j ) S . Only the initial values have to be changed: Set m ^ i j ( 0 ) = 0 if ( i , j ) S and 1 otherwise.
  • Algorithm 2 (factor estimation)

    Assume the same setting as in the classical IPFP. Alternatively, we can estimate the row and column factors separately: Choose initial values b ^ j ( 0 ) := 1 , and for η 1 set

    a ^ i ( η ) = x i + j b ^ j ( η 1 ) , b ^ j ( η ) = x + j i a ^ i ( η )

    Setting m ^ i j ( 2 η ) = a ^ i ( η ) b ^ j ( η ) , the two variants of the algorithm are mathematically equivalent (can be seen by formal induction).

    Notes:

  • In matrix notation, we can write ( m ^ i j ) = a ^ b ^ T , where a ^ = ( a ^ 1 , , a ^ I ) T = lim η a ^ ( η ) and b ^ = ( b ^ 1 , , b ^ J ) T = lim η b ^ ( η ) .
  • The factorization is not unique, since it is m i j = a i b j = ( γ a i ) ( 1 γ b j ) for all γ > 0 .
  • The factor totals remain constant, i.e. i a ^ i ( η ) = i a ^ i ( 1 ) for all η 1 and j b ^ j ( η ) = j b ^ j ( 0 ) for all η 0 .
  • To fit the Q-model, where m i j = 0 a priori for ( i , j ) S , set δ i j = 0 if ( i , j ) S and δ i j = 1 otherwise. Then
  • Obviously, the I-model is a particular case of the Q-model.

    Algorithm 3 (RAS)

    The Problem: Let M := ( m i j ( 0 ) ) R I × J be the initial matrix with nonnegative entries, u R I a vector of specified row marginals (e.i. row sums) and v R J a vector of column marginals. We wish to compute a matrix M ^ = ( m ^ i j ) R I × J similar to M and consistent with the predefined marginals, meaning

    m ^ i + = j = 1 n m ^ i j = u i

    and

    m ^ + j = i = 1 m m ^ i j = v j

    Define the diagonalization operator d i a g : R k R k × k , which produces a (diagonal) matrix with its input vector on the main diagonal and zero elsewhere. Then, for η 0 , set

    M ( 2 η + 1 ) = diag ( r ( η + 1 ) ) M ( 2 η ) M ( 2 η + 2 ) = M ( 2 η + 1 ) diag ( s ( η + 1 ) )

    where

    r i η + 1 = u i j m i j ( 2 η ) s j η + 1 = v j i m i j ( 2 η + 1 )

    Finally, we obtain M ^ = lim η M ( η ) .

    Discussion and comparison of the algorithms

    Although RAS seems to be the solution of an entirely different problem, it is indeed identical to the classical IPFP. In practice, one would not implement actual matrix multiplication, since diagonal matrices are involved. Reducing the operations to the necessary ones, it can easily be seen that RAS does the same as IPFP. The vaguely demanded 'similarity' can be explained as follows: IPFP (and thus RAS) maintains the crossproduct ratios, e.i.

    m i j ( 0 ) m h k ( 0 ) m i k ( 0 ) m h j ( 0 ) = m i j ( η ) m h k ( η ) m i k ( η ) m h j ( η )     η 0  and  i h , j k

    since m i j ( η ) = a i ( η ) b j ( η ) .

    This property is sometimes called structure conservation and directly leads to the geometrical interpretation of contingency tables and the proof of convergence in the seminal paper of Fienberg (1970).

    Nevertheless, direct factor estimation (algorithm 2) is under all circumstances the best way to deal with IPF: Whereas classical IPFP needs

    I J ( 2 + J ) + I J ( 2 + I ) = I 2 J + I J 2 + 4 I J

    elementary operations in each iteration step (including a row and a column fitting step), factor estimation needs only

    I ( 1 + J ) + J ( 1 + I ) = 2 I J + I + J

    operations being at least one order in magnitude faster than classical IPFP.

    Existence and uniqueness of MLEs

    Necessary and sufficient conditions for the existence and uniqueness of MLEs are complicated in the general case (see), but sufficient conditions for 2-dimensional tables are simple:

  • the marginals of the observed table do not vanish (that is, x i + > 0 ,   x + j > 0 ) and
  • the observed table is inseparable (i.e. the table does not permute to a block-diagonal shape).
  • If unique MLEs exist, IPFP exhibits linear convergence in the worst case (Fienberg 1970), but exponential convergence has also been observed (Pukelsheim and Simeone 2009). If a direct estimator (i.e. a closed form of ( m ^ i j ) ) exists, IPFP converges after 2 iterations. If unique MLEs do not exist, IPFP converges toward the so-called extended MLEs by design (Haberman 1974), but convergence may be arbitrarily slow and often computationally infeasible.

    If all observed values are strictly positive, existence and uniqueness of MLEs and therefore convergence is ensured.

    Goodness of fit

    Checking if the assumption of independence is adequate, one uses the Pearson X-squared statistic

    X 2 = i , j ( x i j m i j ^ ) 2 m i j ^

    or alternatively the likelihood-ratio test (G-test) statistic

    G = 2 i , j x i j log   x i j m ^ i j .

    Both statistics are asymptotically X r 2 -distributed, where r = ( I 1 ) ( J 1 ) is the number of degrees of freedom. That is, if the p-values 1 X r 2 ( X 2 ) and 1 X r 2 ( G ) are not too small (> 0.05 for instance), there is no indication to discard the hypothesis of independence.

    Interpretation

    If the rows correspond to different values of property A, and the columns correspond to different values of property B, and the hypothesis of independence is not discarded, the properties A and B are considered independent.

    Example

    Consider a table of observations (taken from the entry on contingency tables):

    For executing the classical IPFP, we first initialize the matrix with ones, leaving the marginals untouched:

    Of course, the marginal sums do not correspond to the matrix anymore, but this is fixed in the next two iterations of IPFP. The first iteration deals with the row sums:

    Note that, by definition, the row sums always constitute a perfect match after odd iterations, as do the column sums for even ones. The subsequent iteration updates the matrix column-wise:

    Now, both row and column sums of the matrix match the given marginals again.

    The p-value of this matrix approximates to p ( X 2 ) 0.1824671 , meaning: gender and left-handedness/right-handedness can be considered independent.

    Implementation

    The R package mipfp (currently in version 3.1) provides a multi-dimensional implementation of the traditional iterative proportional fitting procedure. The package allows the updating of a N-dimensional array with respect to given target marginal distributions (which, in turn can be multi-dimensional).

    Python has an equivalent package, ipfn that can be installed via pip. The package supports numpy and pandas input objects.

    References

    Iterative proportional fitting Wikipedia