Learn R Programming

hypergea (version 1.2.1)

hypergeom.test: Hypergeometric test

Description

Performs exact hypergeometric tests for $I \times J$ and $2 \times 2 \times 2$ contingency tables

Usage

hypergeom.test(x, alternative = "two.sided",
	pval.method = "minimum.likelihood", 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 minimum.likelihood or double. Ignored if alternative is less or gr
nthreads
the number of threads that should be used
...
additional arguments. Currently not used

Value

  • A list with class "htest" containing the following components
  • statisticthe value observed if the cell of interest
  • p.valuethe p-value for the selected test
  • estimatethe odds ratio calculated from x
  • alternativea character string describing the alternative hypothesis
  • methoda character string indicating what type of hypergeometric test was performed
  • conf.intthe 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).

Currently two types of two-sided p-values are implemented. The first one (default) is the minimum-likelihood approach, which is also used by fisher.test, for instance. The second one is the so-called doubling approach.

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)
	CT
	hypergeom.test(CT)

	##########
	## example from Agresti (1992), Table 2
	## Fisher's tea tasting experiment
	# Chi-squared based tests are underestimating p-value
	##########
	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")


	##########
	## 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)
	CT
	hypergeom.test(CT)

Run the code above in your browser using DataLab