fisher.test
, the difference is that
for two-sided tests there are three methods for calculating the exact test, and for each of the three methods
its matching
confidence interval is returned (see details).
For paired binary data resulting in a two by two table, performs an exact McNemar's test.exact2x2(x, y = NULL, or = 1, alternative = "two.sided",
tsmethod = NULL, conf.int = TRUE, conf.level = 0.95,
tol = 0.00001, conditional = TRUE, paired=FALSE,
plot=FALSE)
fisher.exact(x, y = NULL, or = 1, alternative = "two.sided",
tsmethod = "minlike", conf.int = TRUE, conf.level = 0.95,
tol = 0.00001)
blaker.exact(x, y = NULL, or = 1, alternative = "two.sided",
conf.int = TRUE, conf.level = 0.95, tol = 0.00001)
mcnemar.exact(x,y=NULL, conf.level=.95)
x
is a matrix."two.sided"
, "greater"
or "less"
.
if "two.sided" uses method defined by tsmethod.conf.int = TRUE
.exact2x2Plot
"htest"
containing the following components:or
.tsmethod
="minlike").
The central Fisher's exact test defines the p-value as twice the one-sided p-values
(but with a maximum p-value of 1). Blaker's (2000) exact test defines the p-value
as the sum of the tail probibility in the observed tail plus the largest tail probability
in the opposite tail that is not greater than the observed tail probability.
In fisher.test
the p-value uses the two-sample method
associated with tsmethod
="minlike", but the confidence interval method
associated with tsmethod
="central". The probability that the
lower central confidence limit is less than the true odds ratio is bounded by
1-(1-conf.level)/2
for the central intervals, but not for the other two two-sided
methods.
The confidence intervals in for exact2x2
match the test associated
with alternative. In other words, the confidence interval is the smallest interval that contains the confidence set that is
the inversion of the associated test (see Fay, 2010).
The functions fisher.exact
and blaker.exact
are just wrappers for certain
options in exact2x2
.
If x
is a matrix, it is taken as a two-dimensional contingency
table, and hence its entries should be nonnegative integers.
Otherwise, both x
and y
must be vectors of the same
length. Incomplete cases are removed, the vectors are coerced into
factor objects, and the contingency table is computed from these.
P-values are obtained directly using the (central or non-central) hypergeometric
distribution.
The null of conditional
independence is equivalent to the hypothesis that the odds ratio
equals one. alternative = "greater"
is a test of the odds ratio being bigger
than or
.
When paired=TRUE, this denotes there is some pairing of the data. For example,
instead of Group A and Group B, we may have pretest and posttest binary responses.
The proper two-sided test for such a setup is McNemar's Test, which only uses the off-diagonal
elements of the 2x2 table, and tests that both are equal or not. The exact version
is based on the binomial distribution on one of the off-diagonal values conditioned on the total
of both off-diagonal values. We use binom.exact
from the exactci
package, and convert the
p estimates and confidence intervals (see note) to odds ratios (see Breslow and Day, 1980, p. 165). The function
mcnemar.exact
is just a wrapper to call exact2x2
with paired=TRUE, alternative="two.sided",tsmethod="central"
.
One-sided exact McNemar-type tests may be calculated using the exact2x2
function with paired=TRUE
.
For details of McNemar-type tests see Fay (2010, R Journal).fisher.test
or mcnemar.test
## In example 1, notice how fisher.test rejects the null at the 5 percent level,
## but the 95 percent confidence interval on the odds ratio contains 1
## The intervals do not match the p-value.
## In fisher.exact you get p-values and the matching confidence intervals
example1<-matrix(c(6,12,12,5),2,2,dimnames=list(c("Group A","Group B"),c("Event","No Event")))
example1
fisher.test(example1)
fisher.exact(example1,tsmethod="minlike")
fisher.exact(example1,tsmethod="central")
blaker.exact(example1)
## In example 2, this same thing happens, for
## tsmethod="minlike"... this cannot be avoided because
## of the holes in the confidence set.
##
example2<-matrix(c(7,255,30,464),2,2,dimnames=list(c("Group A","Group B"),c("Event","No Event")))
example2
fisher.test(example2)
exact2x2(example2,tsmethod="minlike")
## you can never get a test-CI inconsistency when tsmethod="central"
exact2x2(example2,tsmethod="central")
Run the code above in your browser using DataLab