Code covered by the BSD License  

Highlights from
MyBarnard

Be the first to rate this file! 18 Downloads (last 30 days) File Size: 5.63 KB File ID: #25760
image thumbnail

MyBarnard

by

 

06 Nov 2009 (Updated )

A very compact and fast routine for Barnard's exact test on 2x2 matrix

| Watch this File

File Information
Description

There are two fundamentally different exact tests for comparing the equality of two binomial probabilities – Fisher’s exact test (Fisher, 1925), and Barnard’s exact test (Barnard, 1945). Fisher’s exact test (Fisher, 1925) is the more popular of the two. In fact, Fisher was bitterly critical of Barnard’s proposal for esoteric reasons that we will not go into here. For 2 × 2 tables, Barnard’s test is more powerful than Fisher’s, as Barnard noted in his 1945 paper, much to Fisher’s chagrin (see C.R. Mehta and P. Senchaudhuri: Conditional versus unconditional exact tests for comparing two binomials. www.cytel.com/papers/twobinomials.pdf). Anyway, perhaps due to its computational difficulty the Barnard's is not widely used. This function is completely vectorized and without for...end loops, and so, the computation is very fast. In FEX there is only one other function that computes the Barnard's exact test by Antonio Trujillo-Ortiz.
Using this matrix x=[7 12; 8 3]; switching off the input error checks and display results sections in both functions; the performs are:
L=1000; times=zeros(1,L); for I=1:L, tic; mybarnard(x); times(I)=toc; end, median(times)
ans = 0.0028

L=1000; times=zeros(1,L); for I=1:L, tic; Barnardextest(7,12,8,3); times(I)=toc; end, median(times)
ans = 1.2478

So my function is about 450 times faster.

More details on:
http://www.advancedmcode.org/barnard.html

You can visit my homepage http://home.tele2.it/cardillo
My profile on XING http://www.xing.com/go/invita/13675097
My profile on LinkedIN http://it.linkedin.com/in/giuseppecardillo

Acknowledgements

Barnardextest inspired this file.

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
31 Aug 2013 Giuseppe Cardillo

I dont know. I didnt read the original papers. Maybe now computation power is higher and more accurate and precise

29 Aug 2013 Egon Geerardyn

Shouldn't the P(p) plot (the one shown on the left) be symmetric around p=0.5 as noted in the 1947 paper of Barnard and in the referenced paper?

Updates
06 Nov 2009

change in help section to correctly cite this function

10 Nov 2009

Change in description

23 Dec 2009

Changes in description

22 Mar 2010

I added: 1) the plots of Wald statistics; 2) a flag to choose if the plots must be shown

Contact us