Learn R Programming

nprcgenekeepr (version 3.0.0)

markerObservedHeterozygosity: Compute per-animal observed heterozygosity from marker genotypes

Description

Computes, for each individual, the fraction of its genotyped (non-missing) loci at which it is heterozygous -- the standard "individual/multilocus heterozygosity" statistic conventionally reported per animal (as opposed to the per-locus population framing, which this function does not compute; see markerExpectedHeterozygosity for the population-level counterpart). A raw empirical proportion, not an estimate of a hidden population parameter, so no bias correction applies.

Usage

markerObservedHeterozygosity(genotypeMatrix)

Value

A named numeric vector, one observed-heterozygosity value per id (names taken from rownames(genotypeMatrix)), each in [0, 1]. An individual with no non-missing loci returns NA.

Arguments

genotypeMatrix

a character matrix as returned by buildMarkerGenotypeMatrix: rows are individual ids, columns are loci, and each cell is that individual's two alleles at that locus, sorted and joined by "/" (or NA if not genotyped at that locus).

References

Nei, M. (1973). Analysis of gene diversity in subdivided populations. Proceedings of the National Academy of Sciences USA, 70(12), 3321-3323. tools:::Rd_expr_doi("10.1073/pnas.70.12.3321")

See Also

markerExpectedHeterozygosity, buildMarkerGenotypeMatrix, markerKinship

Examples

Run this code
library(nprcgenekeepr)
markerGenotype <- data.frame(
  id = c("A", "A", "B", "B"),
  locus = c("L1", "L2", "L1", "L2"),
  allele1 = c("A", "A", "A", "A"),
  allele2 = c("A", "B", "B", "B"),
  stringsAsFactors = FALSE
)
genotypeMatrix <- buildMarkerGenotypeMatrix(markerGenotype)
markerObservedHeterozygosity(genotypeMatrix)

Run the code above in your browser using DataLab