chisq.test.simulate {LabApplStat} | R Documentation |
Simulate Chi-squared tests with conditioning
Description
chisq.test.simulate
simulates the chi-squared test for a 2-way contingency tabel.
Usage
chisq.test.simulate(x, conditioning = "total", x0 = NULL, B = 10000)
Arguments
x |
matrix with the contingency table |
conditioning |
character string specifying the simulation scenario. Defaults to |
x0 |
matrix specifying the null distribution. Defaults to |
B |
integer specifying the number of replicates used in the Monte Carlo test. Defaults to 10000. |
Details
Using conditioning="both"
corresponds to selecting simulate.p.value=TRUE
in chisq.test
. However, conditioning on both row and column marginals appears to be rarely justified in real data. Instead conditioning="total"
is the correct choice for testing independence. Similarly, conditioning="row"
is recommended when the row marginals e.g. are fixed by experimental design.
The option x0
has no effect when conditioning on both row and column marginals.
Value
An object of class "htest"
.
Note
The code has not been optimized for speed, and might be slow.
Author(s)
Bo Markussen
See Also
Examples
# The Avadex dataset
Xobs <- matrix(c(2,3,6,40),2,2)
rownames(Xobs) <- c("Avadex +","Avadex -")
colnames(Xobs) <- c("Tumor +","Tumor -")
# In this example only the rows appear to be fixed by experimental design.
# As is seen below, conditioning also on the columns is misleading conservative.
chisq.test.simulate(Xobs,"both")
chisq.test.simulate(Xobs,"row")
chisq.test.simulate(Xobs,"total")
# Conditioning both on row and column marginals is simular to chisq.test().
chisq.test(Xobs,simulate.p.value=TRUE)