# Admixture Graph Manipulation and Fitting

Implements tools for building and visualising admixture graphs and for extracting equations from them. These equations can be compared to f- statistics obtained from data to test the consistency of a graph against data -- for example by comparing the sign of f_4-statistics with the signs predicted by the graph -- and graph parameters (edge lengths and admixture proportions) can be fitted to observed statistics.

The package provides functionality to analyse and test admixture graphs against the f statistics described in the paper Ancient Admixture in Human History, Patterson et al., Genetics, Vol. 192, 1065--1093, 2012.

The f statistics --- f2, f3, and f4 --- extract information about correlations between gene frequencies in different populations (or single diploid genome samples), which can be informative about patterns of gene flow between these populations in form of admixture events. If a graph is constructed as a hypothesis for the relationship between the populations, equations for the expected values of the f statistics can be extracted, as functions of edge lenghs --- representing genetic drift --- and admixture proportions.

This package provides functions for extracting these equations and for fitting them against computed f statistics. It does not currently provide functions for computing the f statistics --- for that we refer to the ADMIXTOOLS software package.

## Example

Below is a quick example of how the package can be used. The example uses data from polar bears and brown bears with a black bear as outgroup and is taken from Genomic evidence of geographically widespread effect of gene flow from polar bears into brown bears.

The BLK sample is the black bear, the PB sample is a polar bear, and the rest are brown bears.

I have taken the f statistics from Table 1 in the paper:

The `D` column is the f4(W,X;Y,Z) statistic and the `Z` column is the Z-values obtained from a blocked jacknife (see Patterson et al. for details).

From the statistics we can see that the ABC bears (Adm, Bar and Chi) are closer related to the polar bears compared to the other brown bears. The paper explains this with gene flow from polar bears into the ABC bears and going further out from there, but we can also explain this by several waves of admixture from ancestral polar bears into brown bears:

## Fitting a graph to data

The graph makes predictions on how the f4 statistics should look. The graph parameters can be fit to observed statistics using the `fit_graph` function:

You can get detailsabout the fit by calling the `summary.agraph_fit` function:

You can make a plot of the fit against the data by calling the `plot.agraph_fit` function:

The plot shows the observed f4 statistics with error bars (in black) plus the predicted values from the graph.

The result of this is a `ggplot2` object that you can modify by adding `ggplot2` commands in the usual way.

Read the vignette `admixturegraph` for more examples.

# Reference manual

1.0.2 by Thomas Mailund, 3 years ago

Authors: Thomas Mailund [cre, aut] , Kalle Leppala [aut] , Svend Nielsen [aut]

Documentation:   PDF Manual