heterozygosity: Heterozygosity at a Locus Using Gene Frequencies

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

This function computes the mean heterozygosity from gene frequencies, and returns optionally the associated variance.

Usage

1
2
heterozygosity(x, variance = FALSE)
H(x, variance = FALSE)

Arguments

x

a vector or a factor.

variance

a logical indicating whether the variance of the estimated heterozygosity should be returned (TRUE), the default being FALSE.

Details

The argument x can be either a factor or a vector. If it is a factor, then it is taken to give the individual alleles in the population. If it is a numeric vector, then its values are taken to be the numbers of each allele in the population. If it is a non-numeric vector, it is a coerced as a factor.

The mean heterozygosity is estimated with:

H = n(1 - SUM (FROM i=1 TO k) p_i^2)/(n - 1)

where n is the number of genes in the sample, k is the number of alleles, and p_i is the observed (relative) frequency of the ith allele.

Value

A numeric vector of length one with the estimated mean heterozygosity (the default), or of length two if the variance is returned.

Author(s)

Emmanuel Paradis

References

Nei, M. (1987) Molecular evolutionary genetics. New York: Columbia University Press.

See Also

theta.s

Examples

1
2
3
4
5
6
7
8
require(adegenet)
data(nancycats)
## convert the data and compute frequencies:
S <- summary(as.loci(nancycats))
## compute H for all loci:
sapply(S, function(x) H(x$allele))
## ... and its variance
sapply(S, function(x) H(x$allele, variance = TRUE))

dwinter/Pegas documentation built on May 15, 2019, 6:21 p.m.