ipf - cup <-colSums(xmed) ; sc <-c /...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
PUBLISH OR PERISH JAN DE LEEUW Suppose A is an n × m matrix with non-negative elements a ij . Also suppose p and p are two vectors with n and m non-negative ele- ments such that n X i = 1 p i = m X j = 1 q j . We now want to find b with n elements and c with m elements such that m X j = 1 b i c j a ij = p i , n X i = 1 b i c j c ij = q j . Thus we rescale rows and columns of A in such a way that the marginals become p and q . Suppose ˜ b and ˜ c are tentative solutions, giving a matrix ˜ A with elements ˜ b i ˜ c j a ij . Update the matrix by a + ij = p i ˜ a i ˜ a ij , which gives a matrix with the correct row sums, and then a ++ ij = q j a + j a + ij , which gives a matrix with the correct column sums. Iterate. Date : May 2, 2007. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 JAN DE LEEUW 1 ipf < - function (x , r= rep (1 , nrow (x) ) , c = rep (1 , ncol (x) ) ,itmax =100,eps=1e - 6,verbose=FALSE) { 2 xold < - x ; i te l < - 1 3 repeat { 4 rup < - rowSums( xold ) ; sr < - r / rup ; xmed < - sr * xold 5
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cup &lt;-colSums(xmed) ; sc &lt;-c / cup ; xnew &lt;-t ( sc * t (xmed) ) 6 if ( verbose ) cat ( 7 &quot; Iteration : &quot; , formatC ( itel , width=3 , format =&quot;d&quot; ) , 8 &quot; rscal : &quot; , formatC ( range ( sr ) , digits =8,width =12, format =&quot; f &quot; ) , 9 &quot; cscla : &quot; , formatC ( range ( sc ) , digits =8,width =12, format =&quot; f &quot; ) , 10 &quot;\n&quot; ) 11 if ( ( max ( abs (xnew-xold ) ) &lt; eps ) | | ( it el == itmax ) ) return (xnew) 12 xold &lt;-xnew ; it el &lt;-i te l+1 13 } 14 } Department of Statistics, University of California, Los Angeles, CA 90095-1554 E-mail address , Jan de Leeuw: deleeuw@stat.ucla.edu URL , Jan de Leeuw: http://gifi.stat.ucla.edu...
View Full Document

This note was uploaded on 01/14/2011 for the course STATS 102A 102A taught by Professor Jandeleeuw during the Fall '10 term at UCLA.

Page1 / 2

ipf - cup &amp;amp;lt;-colSums(xmed) ; sc &amp;amp;lt;-c /...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online