exact.test(data, alternative = "two.sided", npNumbers = 100, beta = 0.001,
interval = FALSE, method = "Z-pooled", model = "Binomial",
cond.row = TRUE, to.plot = TRUE, ref.pvalue=TRUE)method variable lets the user choose the test statistic being used. A brief description for each test statistic is given below (see References for more details):
$\vspace{3 mm}$
Let $\hat{p_1}=x_{11}/n_1$, $\hat{p_2}=x_{21}/n_2$, and $\hat{p}=(x_{11}+x_{21})/(n_1+n_2)$.
$\vspace{3 mm}$
Z-unpooled (or Wald):
$$Z_u(x_{11},x_{21})=\frac{\hat{p_2}-\hat{p_1}}{\sqrt{\frac{\hat{p_1}(1-\hat{p_1})}{n_1}+\frac{\hat{p_2}(1-\hat{p_2})}{n_2}}}$$
Z-pooled (or Score):
$$Z_p(x_{11},x_{21})=\frac{\hat{p_2}-\hat{p_1}}{\sqrt{\frac{\hat{p}(1-\hat{p})}{n_1}+\frac{\hat{p}(1-\hat{p})}{n_2}}}$$
Santner and Snell:
$$D(x_{11},x_{21})=\hat{p_2}-\hat{p_1}$$
Boschloo:
Uses the p-value from Fisher's exact test as the test statistic.
$\vspace{3 mm}$
CSM:
Starts with the most extreme table and adds other 'as or more extreme' tables one step at a time
by maximizing the summand of the p-value function. This approach can be computationally intensive.
$\vspace{0 mm}$
CSM modified:
Starts with all tables that must be more extreme and adds other 'as or more extreme' tables one step at a time
by maximizing the summand of the p-value function. This approach can be computationally intensive.
$\vspace{3 mm}$
CSM approximate:
Maximizes the summand of the p-value function for each possible table. Thus, the test statistic is the p-value function without the summation.
This approach is less computationally intensive than the CSM test because the maximization is not repeated at each step.
$\vspace{3 mm}$
The supremum of the common success probability is taken over all values between 0 and 1. Another approach, proposed by Berger and Boos, is
to take the supremum over a Clopper-Pearson confidence interval. This approach adds a small penalty to the p-value to ensure a level-$\alpha$ test,
but eliminates unlikely probabilities from inflating the p-value. The p-value function becomes:
$$P(X|p)= \left(\sup_{p \in C_\beta} \sum_{T(X) \geq T(X_0)} {n_1 \choose x_{11}} {n_2 \choose x_{21}} p^{x_{11}+x_{21}} (1-p)^{x_{12}+x_{13}}\right) + \beta$$
where $C_\beta$ is the $100(1-\beta)%$ confidence interval of $p$
$\vspace{3 mm}$
There are many ways to define the two-sided p-value; this code uses the fisher.test() approach by summing the
probabilities for both sides of the table.fisher.test, data<-matrix(c(7,8,12,3),2,2,byrow=TRUE)
exact.test(data,alternative="less",to.plot=TRUE)
exact.test(data,alternative="two.sided",interval=TRUE,beta=0.001,npNumbers=100,method="Z-pooled",
to.plot=FALSE)
exact.test(data,alternative="two.sided",interval=TRUE,beta=0.001,npNumbers=100,method="Boschloo",
to.plot=FALSE)
#Example from Barnard's (1947) appendix:
data<-matrix(c(4,0,3,7),2,2,dimnames=list(c("Box 1","Box 2"),c("Defective","Not Defective")))
exact.test(data,method="CSM",alternative="two.sided")
data<-matrix(c(6,8,4,3),2,2,byrow=TRUE)
exact.test(data,model="Multinomial",alternative="less",method="Z-pooled")Run the code above in your browser using DataLab