Re: [R] Fisher's test

From: Peter Ehlers <ehlers_at_ucalgary.ca>
Date: Fri, 01 Apr 2011 12:57:12 -0700

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



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. Received on Fri 01 Apr 2011 - 19:59:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 01 Apr 2011 - 21:00:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive