[R] Fisher's test

Peter Ehlers ehlers at ucalgary.ca
Fri Apr 1 21:57:12 CEST 2011


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



More information about the R-help mailing list