[R] Getting all possible contingency tables
David Winsemius
dwinsemius at comcast.net
Sat Dec 1 17:37:48 CET 2012
On Dec 1, 2012, at 7:28 AM, Christofer Bogaso wrote:
> Thanks Bert for your reply.
>
> I am trying to understand/visualize the Sample Chi-Squared
> Statistic's Null distribution. Therefore I need all possible
> Contingency tables under Independence case.
>
> What could be better way to visualize that?
In your quest for enlightenment, consider looking at the example in:
?r2dtable
--
David.
>
> Thanks and regards,
>
> On 01 December 2012 20:03:00, Bert Gunter wrote:
>> Christopher:
>>
>> Don't do this!
>>
>> If I understand you correctly, you want FIsher's exact test. This is
>> already available in R, using far smarter algorithms then you
>> would. See:
>>
>> ?fisher.test
>>
>> -- Bert
>>
>> On Sat, Dec 1, 2012 at 5:48 AM, Christofer Bogaso
>> <bogaso.christofer at gmail.com <mailto:bogaso.christofer at gmail.com>>
>> wrote:
>>
>> 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
>> <mailto:bogaso.christofer at gmail.com>
>> Sent: Sat, 01 Dec 2012 18:10:15 +0545
>> To: r-help at r-project.org <mailto: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,
>>
>>
David Winsemius, MD
Alameda, CA, USA
More information about the R-help
mailing list