[R] Getting all possible contingency tables

Christofer Bogaso bogaso.christofer at gmail.com
Sat Dec 1 14:48:09 CET 2012


Thanks John for your reply. However still not clear how I should proceed.

My goal is to generate all possible contingency tables. Basically I want 
to see the distribution of Chi-squared Statistic under independence (NULL).

So I was thinking if I can generate all possible permutation of integer 
numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is there any R 
function to do that?

Thanks and regards,


On 01-12-2012 18:39, John Kane wrote:
> Are you basically asking for all possible permutations of the table?  If so see ?permn in the combinat package.
>
> John Kane
> Kingston ON Canada
>
>
>> -----Original Message-----
>> From: bogaso.christofer at gmail.com
>> Sent: Sat, 01 Dec 2012 18:10:15 +0545
>> To: r-help at r-project.org
>> Subject: [R] Getting all possible contingency tables
>>
>> Hello all,
>>
>> Let say I have 2-way contingency table:
>>
>> Tab <- matrix(c(8, 10, 12, 6), nr = 2)
>>
>> and the Chi-squared test could not reject the independence:
>>
>>   > chisq.test(Tab)
>>
>>           Pearson's Chi-squared test with Yates' continuity correction
>>
>> data:  Tab
>> X-squared = 1.0125, df = 1, p-value = 0.3143
>>
>>
>> However I want to get all possible contingency tables under this
>> independence scenario (one of them would obviously be the given table
>> as, we could not reject the independence), and for each such table I
>> want to calculate the Ch-sq statistic.
>>
>> Can somebody help me how to generate all such tables?
>>
>> Thanks and regards,
>>
>> ______________________________________________
>> 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.
> ____________________________________________________________
> FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
> Visit http://www.inbox.com/photosharing to find out more!
>
>
>




More information about the R-help mailing list