Skip to contents

Computes Nei's gene diversity (the standard \(He = 1 - \sum p_i^2\) form, where \(p_i\) is the population frequency of allele \(i\) at a locus) for each locus from the non-missing genotype calls at that locus, plus the unweighted mean across loci as a population-wide summary. This is the plain (uncorrected) estimator – the small-sample-size-corrected variant (Nei & Roychoudhury 1974) is not computed here.

Usage

markerExpectedHeterozygosity(genotypeMatrix)

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).

Value

A list with two elements: perLocus, a named numeric vector of expected heterozygosity per locus (names taken from colnames(genotypeMatrix)); and meanHe, the unweighted mean of perLocus across all loci.

References

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

Examples

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)
markerExpectedHeterozygosity(genotypeMatrix)
#> $perLocus
#>    L1    L2 
#> 0.375 0.500 
#> 
#> $meanHe
#> [1] 0.4375
#>