Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

heterozygosity

Heterozygosity at a Locus Using Gene Frequencies


Description

Thes functions compute the mean heterozygosity(ies) from gene frequencies, and return optionally the associated variance(s).

Usage

H(x, ...)
## S3 method for class 'loci'
H(x, variance = FALSE, observed = FALSE, ...)
## Default S3 method:
H(x, variance = FALSE, ...)

heterozygosity(x, variance = FALSE)

Arguments

x

an object of class "loci", or vector or a factor.

variance

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

observed

a logical specifying whether to calculate the observed heterozygosity.

...

unused.

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

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

For the "loci" method: a numeric matrix with one, two, or three columns with a row for each locus and the values of heterozygosity as columns.

Author(s)

Emmanuel Paradis

References

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

See Also

Examples

data(jaguar)
H(jaguar, TRUE, TRUE)
## use the (old) default method:
## convert the data and compute frequencies:
S <- summary(jaguar)
## compute H for all loci:
sapply(S, function(x) H(x$allele))
## ... and its variance
sapply(S, function(x) H(x$allele, variance = TRUE))

pegas

Population and Evolutionary Genetics Analysis System

v1.0
GPL (>= 2)
Authors
Emmanuel Paradis [aut, cre, cph] (<https://orcid.org/0000-0003-3092-2199>), Thibaut Jombart [aut, cph] (<https://orcid.org/0000-0003-2226-8692>), Zhian N. Kamvar [aut, cph] (<https://orcid.org/0000-0003-1458-7108>), Brian Knaus [aut, cph] (<https://orcid.org/0000-0003-1665-4343>), Klaus Schliep [aut, cph] (<https://orcid.org/0000-0003-2941-0161>), Alastair Potts [aut, cph] (<https://orcid.org/0000-0003-0919-7279>), David Winter [aut, cph] (<https://orcid.org/0000-0002-6165-0029>)
Initial release
2021-04-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.