Skip to content
Back to formatted view

Raw Message

Message-ID: <4D962E18.4090802@ucalgary.ca>
Date: 2011-04-01T19:57:12Z
From: Peter Ehlers
Subject: Fisher's test
In-Reply-To: <BANLkTi=k1_PhTBjYWVWimH4g6g5pwaaijA@mail.gmail.com>

On 2011-04-01 10:19, Jim Silverton wrote:
> I have a matrix with 2 columns and I want to do fishers exact test for these
> with the totals for each row being 100 say.
>
> The data has the form:
> 23  12
> 32  21
> 12  2
>
> and these represents the tables:
>
> 23 12
> 77 88
>
> 32  21
> 78  79
>
> 12   2
> 88  98
>
>
> How do I use apply to speed up aclculation of the fisher.exact test?
>

  apply(yourMatrix, 1, function(x) fisher.test(cbind(x, 100 - x)))

or, if you only want the P-value:

  apply(yourMatrix, 1,
        function(x) fisher.test(cbind(x, 100 - x))$p.value)

Peter Ehlers