Learn R Programming

hypergea (version 1.3.1)

hypergeom.test: Hypergeometric test

Description

Performs exact hypergeometric tests for $IxJ$ and $2x2x2$ contingency tables

Usage

hypergeom.test(x, alternative = "two.sided", pval.method = "fisheR", nthreads = 2, ...)

Arguments

x
an integer array (or matrix) without missing values
alternative
a character string specifying the alternative hypothesis, must be one of “two.sided” (default), “greater” or “less”.
pval.method
a character string specifying which approach should be used to determine the p-value in a two-sided test. Can be “fisheR”, “minimum.likelihood” or “double”. Ignored if ‘alternative’ is “less” or “greater”
nthreads
the number of threads that should be used
...
additional arguments. Currently not used

Value

A list with class ‘"htest"’ containing the following components
statistic
the value observed if the cell of interest
p.value
the p-value for the selected test
estimate
the sample odds ratio calculated from ‘x’
alternative
a character string describing the alternative hypothesis
method
a character string indicating what type of hypergeometric test was performed
conf.int
the 95% confidence interval of the odds ratio

Source

The code for 2x2x2 hypergeometric test is a C translation of the Fortran algorithm of Zelterman (1999).

Details

There is a lot of discussion about the correct way to calculate a p-value in a two sided test. Thus, several alternatives are possible (see Agresti (1992) for a short discussion and further references).

Three types of two-sided p-values are implemented. The first one (default) is the approach used by the Fisher's test implementation In R. It is currently used only for $2x2$ tables. It is similar to the minimum-likelihood approach, which is also usable. The third one is the so-called doubling approach. In case of tables with I!=2 and J=!2 or $2x2x2$ tables instead of the fisheR implementation the minimum-likelihood implementation is applied.

References

Agresti, Alan (1992) A survey of exact inference for contingency tables. Statistical Science Vol. 7, No. 1 (Feb., 1992), pp. 131-153

Zelterman, Daniel (1999) Models for Discrete Data. Oxford University Press

See Also

fisher.test to calculate p-values for $2\times 2$ tables

Examples

Run this code
	##########
	## example from Zelterman (1999), p. 119, Table 4.1
	## mice were exposed to a fungicide (or not), some have a tumor
	##########
	dmn <- list(Tumor=c('y', 'n'), Exposition=c('y', 'n'))
	CT <- matrix(c(4,12,5,74), nrow=2, dimnames=dmn)
	## Not run: CT
	hypergeom.test(CT)

	## Not run: 
# 	##########
# 	## example from Agresti (1992), Table 2
# 	## Fisher's tea tasting experiment
# 	##########
# 	dmn <- list('poured first'=c('m', 't'), guess=c('m', 't'))
# 	CT <- matrix(c(3,1,1,3), nrow=2, dimnames=dmn)
# 	hypergeom.test(CT, alternative="two.sided")
# 	hypergeom.test(CT, alternative="two.sided", pval.method="double")
# 	hypergeom.test(CT, alternative="less")
# 	hypergeom.test(CT, alternative="greater")
# 	## End(Not run)


	##########
	## example from Zelterman (1999), p. 44, Table 1.2
	## Response to three drugs
	##########
	dmn <- list(A=c('F', 'U'), B=c('F', 'U'), C=c('F', 'U'))
	CT <- array(c(6,16,2,4,2,4,6,6), dim=c(2,2,2), dimnames=dmn)
	## Not run: CT
	hypergeom.test(CT)

Run the code above in your browser using DataLab