# Composition Statistics (`skbio.stats.composition`)

This module provides functions for compositional data analysis.

Many ‘omics datasets are inherently compositional - meaning that they are best interpreted as proportions or percentages rather than absolute counts.

Formally, \(x\) is a composition if \(\sum_{i=0}^D x_{i} = c\) and \(x_{i} > 0\), \(1 \leq i \leq D\) and \(c\) is a real valued constant and there are \(D\) components for each composition. In this module \(c=1\). Compositional data can be analyzed using Aitchison geometry. [R234]

However, in this framework, standard real Euclidean operations such as addition and multiplication no longer apply. Only operations such as perturbation and power can be used to manipulate this data.

This module allows two styles of manipulation of compositional data. Compositional data can be analyzed using perturbation and power operations, which can be useful for simulation studies. The alternative strategy is to transform compositional data into the real space. Right now, the centre log ratio transform (clr) and the isometric log ratio transform (ilr) [R235] can be used to accomplish this. This transform can be useful for performing standard statistical tools such as parametric hypothesis testing, regressions and more.

The major caveat of using this framework is dealing with zeros. In the Aitchison geometry, only compositions with nonzero components can be considered. The multiplicative replacement technique [R236] can be used to substitute these zeros with small pseudocounts without introducing major distortions to the data.

## Functions

`closure`(mat) | State: Experimental as of 0.4.0.
`multiplicative_replacement`(mat[, delta]) | Replace all zeros with small non-zero values
`perturb`(x, y) | State: Experimental as of 0.4.0.
`perturb_inv`(x, y) | State: Experimental as of 0.4.0.
`power`(x, a) | State: Experimental as of 0.4.0.
`inner`(x, y) | State: Experimental as of 0.4.0.
`clr`(mat) | State: Experimental as of 0.4.0.
`clr_inv`(mat) | State: Experimental as of 0.4.0.
`ilr`(mat[, basis, check]) | State: Experimental as of 0.4.0.
`ilr_inv`(mat[, basis, check]) | State: Experimental as of 0.4.0.
`centralize`(mat) | Center data around its geometric average.
`ancom`(table, grouping[, alpha, tau, theta, ...]) | Performs a differential abundance test using ANCOM.

## References

[R234] | V. Pawlowsky-Glahn, “Lecture Notes on Compositional Data Analysis” (2007)

[R235] | J. J. Egozcue., “Isometric Logratio Transformations for Compositional Data Analysis” Mathematical Geology, 35.3 (2003)

[R236] | J. A. Martin-Fernandez, “Dealing With Zeros and Missing Values in Compositional Data Sets Using Nonparametric Imputation”, Mathematical Geology, 35.3 (2003)

## Examples

    >>> import numpy as np

Consider a very simple environment with only 3 species. The species in the environment are equally distributed and their proportions are equivalent:

    >>> otus = np.array([1./3, 1./3., 1./3])

Suppose that an antibiotic kills off half of the population for the first two species, but doesn’t harm the third species. Then the perturbation vector would be as follows

    >>> antibiotic = np.array([1./2, 1./2, 1])

And the resulting perturbation would be

    >>> perturb(otus, antibiotic)
    array([ 0.25,  0.25,  0.5 ])