# [R] two sample binomial test

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu Jun 24 11:29:21 CEST 2010

```On 24-Jun-10 06:36:39, associatedboy wrote:
> I wanted to know if there is a way to perform a two sample binomial
> test in R.  I know you can use the proportion test i.e.:
> prop.test(c(19,5),c(53,39),p=NULL,alternative="two.sided"). But I was
> looking to use the exact binomial test, binom.test, however when I have
> tried replacing prop.test with binom.test I get an error.  Is there any
> way to do this?
> --

If you are looking for an exact test to compare two binomial proportions,
you could consider the Fisher Exact Test, which is provided by the
function fisher.test applied to the corresponding 2x2 table, e.g.
(taking your c(19,5),c(53,39) to be "successes" and "n" respectively):

fisher.test(matrix(c(19, 53-19, 5, 39-5), nrow=2))
#         Fisher's Exact Test for Count Data
# data:  matrix(c(19, 53 - 19, 5, 39 - 5), nrow = 2)
# p-value = 0.01625
# alternative hypothesis: true odds ratio is not equal to 1
# 95 percent confidence interval:
#   1.175385 14.351625
# sample estimates:
# odds ratio
#    3.74751

Note, however, that the P-value is comnputed conditionally on the
row and column margins being constant, i.e. it is based on the
distribution of X where the table is

Grp1   Grp2
Y=1:  19+X    5-X
Y=0:  34-X   34+X

the observed table being the one where X=0. However, this is a
natural context for an "exact" test, since it considers all the
possible re-assignments of the fixed number (24) of "Y=1" cases
between Grp1 and Grp2, holding the sizes of Grp1 and Grp2 fixed.
(Hence X cannot exceed 5, and can be as low as 0, so the possible
re-assignments are X=0,1,2,3,4,5).

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 24-Jun-10                                       Time: 10:29:19
------------------------------ XFMail ------------------------------

```