Learn R Programming

LabApplStat (version 1.4.4)

chisq.test.simulate: 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)

Value

An object of class "htest".

Arguments

x

matrix with the contingency table

conditioning

character string specifying the simulation scenario. Defaults to "total". Other possible scenarios are "row", "col", and "both".

x0

matrix specifying the null distribution. Defaults to NULL, in which case the null is estimated from the observed data x.

B

integer specifying the number of replicates used in the Monte Carlo test. Defaults to 10000.

Author

Bo Markussen

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.

See Also

Examples

Run this code
# 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)

Run the code above in your browser using DataLab