[R] ipf function in R

(Ted Harding) Ted.Harding at manchester.ac.uk
Wed Mar 5 11:27:08 CET 2008


On 05-Mar-08 07:14:28, Chandra Shah wrote:
> Hi
> I have a 3 x 2 contingency table:
> 10 20
> 30 40
> 50 60
> I want to update the frequencies to new marginal totals:
> 100 130
> 40 80 110
> I want to use  the ipf (iterative proportional fitting) function
> which is apparently in the cat package.
> Can somebody please advice me how to input this data and invoke
> ipf in R to obtain an updated contingency table?
> Thanks.
> By the way I am quite new to R.

It is not clear from your description what you really want to do.
Hence, not clear whether you should be using ipf() to do it!

The purpose of ipf() in the 'cat' package is very simple:
You suppply a complete contingency table, and specify the
order of interactions you want to include in the fit (using
the "margins" parameter in ipf()); and then the value of ipf()
is a table of the fitted (expected) values corresponding to
a model of the type you have specified, fitted by maximum
likelihood.

Your task seems to be different. If I understand your statement.
it looks as though you want to find a,b,c,d such that

  10+a  20+c | 40
  30+b  40+d | 80
  50    60   |110
-------------+---
 100   130   |230

or, since there are row and column constraints on a,b,c,d:

  10+a  30-a | 40
  40-a  40+a | 80
  50    60   |110
-------------+---
 100   130   |230

so then the task would be to find a.

But now it depends on what you would mean by "find a".

You could treat 'a' as an unknown parameter, and fit it
by maximum likelihood under various assumptions about the
dependence between rows and columns (e.g. that the log
odds-ratios have particular values).

Or perhaps (and here is where ipf() may come in) for a
given choice of 'a' you could submit the resulting table
to ipf() and compute chisq from the resulting fitted
values and the given "observed" values; then seek the
value of 'a' which minimises chisq.

However, it's not really possible to advise in more detail
without being sure of what you are trying to do. Above,
I am only guessing!

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 05-Mar-08                                       Time: 10:26:57
------------------------------ XFMail ------------------------------



More information about the R-help mailing list