Be the first to rate this file! 53 downloads (last 30 days) File Size: 5.15 KB File ID: #25760

MyBarnard

by Giuseppe Cardillo

 

06 Nov 2009 (Updated 10 Nov 2009)

Code covered by BSD License  

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

Download Now | 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

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Barnardextest

MATLAB release MATLAB 7.6 (R2008a)
Zip File Content  
Other Files license.txt,
mybarnard.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
06 Nov 2009

change in help section to correctly cite this function

10 Nov 2009

Change in description

Tag Activity for this File
Tag Applied By Date/Time
statistics Giuseppe Cardillo 06 Nov 2009 09:39:29
barnards exact test Giuseppe Cardillo 06 Nov 2009 09:39:29
unconditional test Giuseppe Cardillo 06 Nov 2009 09:39:29
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com