skbio.stats.composition.sbp_basis

skbio.stats.composition.sbp_basis(sbp)[source]

State: Experimental as of 0.5.5. Builds an orthogonal basis from a sequential binary partition (SBP). As explained in [1], the SBP is a hierarchical collection of binary divisions of compositional parts. The child groups are divided again until all groups contain a single part. The SBP can be encoded in a \((D - 1) \times D\) matrix where, for each row, parts can be grouped by -1 and +1 tags, and 0 for excluded parts. The sbp_basis method was originally derived from function gsi.buildilrBase() found in the R package compositions [2]. The ith balance is computed as follows

\[b_i = \sqrt{ \frac{r_i s_i}{r_i+s_i} } \ln \left( \frac{g(x_{r_i})}{g(x_{s_i})} \right)\]

where \(b_i\) is the ith balance corresponding to the ith row in the SBP, \(r_i\) and \(s_i\) and the number of respectively +1 and -1 labels in the ith row of the SBP and where \(g(x) = (\prod\limits_{i=1}^{D} x_i)^{1/D}\) is the geometric mean of \(x\).

Parameters:

sbp (np.array, int) – A contrast matrix, also known as a sequential binary partition, where every row represents a partition between two groups of features. A part labelled +1 would correspond to that feature being in the numerator of the given row partition, a part labelled -1 would correspond to features being in the denominator of that given row partition, and 0 would correspond to features excluded in the row partition.

Returns:

An orthonormal basis in the Aitchison simplex

Return type:

numpy.array

Examples

>>> import numpy as np
>>> sbp = np.array([[1, 1,-1,-1,-1],
...                 [1,-1, 0, 0, 0],
...                 [0, 0, 1,-1,-1],
...                 [0, 0, 0, 1,-1]])
...
>>> sbp_basis(sbp)
array([[ 0.54772256,  0.54772256, -0.36514837, -0.36514837, -0.36514837],
       [ 0.70710678, -0.70710678,  0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  0.81649658, -0.40824829, -0.40824829],
       [ 0.        ,  0.        ,  0.        ,  0.70710678, -0.70710678]])

References