View source: R/heterozygosity.R
heterozygosity | R Documentation |
Thes functions compute the mean heterozygosity(ies) from gene frequencies, and return optionally the associated variance(s).
H(x, ...)
## S3 method for class 'loci'
H(x, variance = FALSE, observed = FALSE, ...)
## Default S3 method:
H(x, variance = FALSE, ...)
heterozygosity(x, variance = FALSE)
x |
an object of class |
variance |
a logical indicating whether the variance of the
estimated heterozygosity should be returned ( |
observed |
a logical specifying whether to calculate the observed heterozygosity. |
... |
unused. |
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:
\hat{H} = \frac{n}{n-1} \left(1 - \sum_{i=1}^k p_i^2 \right)
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 i
th allele.
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.
Emmanuel Paradis
Nei, M. (1987) Molecular evolutionary genetics. New York: Columbia University Press.
theta.s
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.