[R] Sample all possible contingency tables both margin fixed

peter dalgaard pdalgd at gmail.com
Tue Jun 24 19:58:59 CEST 2014


On 24 Jun 2014, at 16:41 , Tahira Jamil <tahjamil at gmail.com> wrote:

> Hi,
> 
> I am interested in generating all possible contingency table (2 by 2) with fixed row margins and column margins. Can anyone help me. 
> 


It's pretty easy, just find one compatible solution and add or subtract

1 -1
-1  1

until one of the numbers would go negative. Or put differently, if you know one entry, you know the other three, so it is just a matter of working out the range of (say) possible top-left entries.

With more than 2x2 tables it is much harder, but fisher.test() does it internally.

-pd


> Best regards,
> Tahira 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list