Title: | Barnard's Unconditional Test |
---|---|
Description: | Barnard's unconditional test for 2x2 contingency tables. |
Authors: | Kamil Erguler |
Maintainer: | Kamil Erguler <[email protected]> |
License: | GPL-2 |
Version: | 1.8.1 |
Built: | 2025-02-04 05:09:29 UTC |
Source: | https://github.com/kerguler/barnard |
This package implements the barnard.test
function for performing Barnard's unconditional test of superiority.
This is a more powerful alternative of Fisher's exact test for 2x2 contingency tables. The test, in its current implementation, uses Wald statistics as a measure of difference between two binomial proportions.
Kamil Erguler, Post-doctoral Fellow, EEWRC, The Cyprus Institute [email protected]
Barnard, G.A. (1945) A new test for 2x2 tables. Nature, 156:177.
Barnard, G.A. (1947) Significance tests for 2x2 tables. Biometrika, 34:123-138.
Barnard's unconditional test for superiority applied to 2x2 contingency tables using Score or Wald statistics for the difference between two binomial proportions.
barnard.test(n1, n2, n3, n4, dp = 0.001, pooled = TRUE)
barnard.test(n1, n2, n3, n4, dp = 0.001, pooled = TRUE)
n1 , n2 , n3 , n4
|
Elements of the 2x2 contingency table |
dp |
The resolution to search for the nuisance parameter |
pooled |
Z statistic with pooled (Score) or unpooled (Wald) variance |
For a 2x2 contingency table, such as , the normalized difference in proportions between the two categories, given in each column, can be written with pooled variance (Score statistic) as
where ,
,
,
and
. Alternatively, with unpooled variance (Wald statistic), the difference in proportions can we written as
The probability of observing is
where is the unknown nuisance parameter.
Barnard's test considers all tables with category sizes and
for a given
. The p-value is the sum of probabilities of the tables having a score in the rejection region, e.g. having significantly large difference in proportions for a two-sided test. The p-value of the test is the maximum p-value calculated over all
between 0 and 1.
statistic.table |
The contingency tables considered in the analysis represented by 'n1' and 'n2', their scores, and whether they are included in the one-sided (1), two-sided (2) tests, or not included at all (0) |
nuisance.matrix |
Nuisance parameters, |
dp |
The resolution of the search space for the nuisance parameter |
contingency.matrix |
The observed 2x2 contingency table |
alternative |
One sided or two sided test |
statistic |
The standardized difference between the observed proportions |
nuisance.parameter |
The nuisance parameter where the p-value is maximized |
p.value |
The p-value for the observed contingency table |
pooled |
Variance estimator of the Z statistic |
I am indebted to Peter Calhoun for helping to test the performance and the accuracy of the code. I also thank Rodrigo Duprat, Long Qu, and Nicolas Sounac for their valuable comments. The accuracy has been tested with respect to the existing MATLAB and R implementations as well as the results of StatXact. I have largely been influenced by the works of Trujillo-Ortiz etal. (2004), Cardillo G. (2009), and Galili T. (2010).
Kamil Erguler, Post-doctoral Fellow, EEWRC, The Cyprus Institute [email protected]
Barnard, G.A. (1945) A new test for 2x2 tables. Nature, 156:177.
Barnard, G.A. (1947) Significance tests for 2x2 tables. Biometrika, 34:123-138.
Suissa, S. and Shuster, J. J. (1985), Exact Unconditional Sample Sizes for the 2x2 Binomial Trial, Journal of the Royal Statistical Society, Ser. A, 148, 317-327.
Cardillo G. (2009) MyBarnard: a very compact routine for Barnard's exact test on 2x2 matrix. URL http://www.mathworks.com/matlabcentral/fileexchange/25760
Galili T. (2010) URL http://www.r-statistics.com/2010/02/barnards-exact-test-a-powerful-alternative-for-fishers-exact-test-implemented-in-r/
Lin C.Y., Yang M.C. (2009) Improved p-value tests for comparing two independent binomial proportions. Communications in Statistics-Simulation and Computation, 38(1):78-91.
Trujillo-Ortiz, A., R. Hernandez-Walls, A. Castro-Perez, L. Rodriguez-Cardozo N.A. Ramos-Delgado and R. Garcia-Sanchez. (2004). Barnardextest:Barnard's Exact Probability Test. A MATLAB file. [WWW document]. URL http://www.mathworks.com/
barnard.test(8,14,1,3) ## Plotting the search for the nuisance parameter for a one-sided test bt<-barnard.test(8,14,1,3) plot(bt$nuisance.matrix[,1:2], t="l",xlab="nuisance parameter",ylab="p-value") ## Plotting the tables included in the p-value bt<-barnard.test(40,14,10,30) bts<-bt$statistic.table plot(bts[,1],bts[,2], col=hsv(bts[,4]/4,1,1), t="p",xlab="n1",ylab="n2") ## Plotting the difference between pooled and unpooled tests bts<-barnard.test(40,14,10,30,pooled=TRUE)$statistic.table btw<-barnard.test(40,14,10,30,pooled=FALSE)$statistic.table plot(bts[,1],bts[,2], col=c("black","white")[1+as.numeric(bts[,4]==btw[,4])], t="p",xlab="n1",ylab="n2")
barnard.test(8,14,1,3) ## Plotting the search for the nuisance parameter for a one-sided test bt<-barnard.test(8,14,1,3) plot(bt$nuisance.matrix[,1:2], t="l",xlab="nuisance parameter",ylab="p-value") ## Plotting the tables included in the p-value bt<-barnard.test(40,14,10,30) bts<-bt$statistic.table plot(bts[,1],bts[,2], col=hsv(bts[,4]/4,1,1), t="p",xlab="n1",ylab="n2") ## Plotting the difference between pooled and unpooled tests bts<-barnard.test(40,14,10,30,pooled=TRUE)$statistic.table btw<-barnard.test(40,14,10,30,pooled=FALSE)$statistic.table plot(bts[,1],bts[,2], col=c("black","white")[1+as.numeric(bts[,4]==btw[,4])], t="p",xlab="n1",ylab="n2")
Previous version of Barnard's unconditional test for superiority which used Z-statistic with pooled variance for the difference between two binomial proportions in a 2x2 contingency table. Please use the 'barnard.test' instead.