composition_stats.sbp_basis¶
- composition_stats.sbp_basis(sbp)¶
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
- numpy.array
An orthonormal basis in the Aitchison simplex
References
- 1
Parent, S.É., Parent, L.E., Egozcue, J.J., Rozane, D.E., Hernandes, A., Lapointe, L., Hébert-Gentile, V., Naess, K., Marchand, S., Lafond, J., Mattos, D., Barlow, P., Natale, W., 2013. The plant ionome revisited by the nutrient balance concept. Front. Plant Sci. 4, 39, http://dx.doi.org/10.3389/fpls.2013.00039.
- 2
van den Boogaart, K. Gerald, Tolosana-Delgado, Raimon and Bren, Matevz, 2014. compositions: Compositional Data Analysis. R package version 1.40-1. https://CRAN.R-project.org/package=compositions.
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.31209907, 0.31209907, 0.12526729, 0.12526729, 0.12526729], [ 0.36733337, 0.08930489, 0.18112058, 0.18112058, 0.18112058], [ 0.17882092, 0.17882092, 0.40459293, 0.11888261, 0.11888261], [ 0.18112058, 0.18112058, 0.18112058, 0.36733337, 0.08930489]])