---
title: "By-Locus Summaries"
author: "Eric Archer"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{2. By-Locus Summaries}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---
```{r echo = FALSE, message = FALSE}
options(digits = 2)
library(strataG)
```
There are several by-locus summary functions available for _gtypes_ objects. Given some sample microsatellite data:
```{r}
data(msats.g)
msats <- stratify(msats.g, "broad")
msats <- msats[, locNames(msats)[1:4], ]
```

One can calculate the following summaries:

The number of alleles at each locus:
```{r}
numAlleles(msats)
```

The number of samples with missing data at each locus:
```{r}
numMissing(msats)
```
which can also be expressed as a proportion of samples with missing data:
```{r}
numMissing(msats, prop = TRUE)
```

The allelic richness, or the average number of alleles per sample:
```{r}
allelicRichness(msats)
```

The observed and expected heterozygosity:
```{r}
obsvdHet(msats)
exptdHet(msats)
```

The proportion of alleles that are unique (present in only one sample):
```{r}
propUniqueAlleles(msats)
```

The value of theta based on heterozygosity:
```{r}
theta(msats)
```

These measures are all calculated in the _summarizeLoci_ function and returned as a matrix. This function also allows you to calculate the measures for each stratum separately, which returns a list for each stratum:
```{r}
summarizeLoci(msats)
summarizeLoci(msats, by.strata = TRUE)
```

One can also obtain the allelic frequencies for each locus overall and by-strata by:
```{r}
alleleFreqs(msats)
alleleFreqs(msats, by.strata = TRUE)
```
