skbio.stats.composition.rclr_inv#

skbio.stats.composition.rclr_inv(mat, axis=-1, validate=True)[source]#

Perform inverse robust centre log ratio (RCLR) transformation.

Added in version 0.7.4.

This function transforms RCLR-transformed data back to compositional space. Non-NaN values are exponentiated and closed to sum to 1, while NaN values are interpreted as unobserved components and become zeros in the output.

For a transformed composition \(x\), let \(S\) be the set of observed (non-NaN) components. The inverse transformation is

\[\begin{split}rclr^{-1}(x)_i = \begin{cases} \displaystyle \frac{\exp(x_i)}{\sum_{j \in S} \exp(x_j)}, & i \in S, \\ 0, & i \notin S. \end{cases}\end{split}\]
Parameters:
matarray_like of shape (…, n_components, …)

A matrix of RCLR-transformed data. NaN values represent unobserved components.

axisint, optional

Axis along which inverse RCLR transformation will be performed. Each vector on this axis is considered as an RCLR-transformed composition. Default is the last axis (-1).

validatebool, optional

Check that each composition contains at least one observed value and that its observed values are centered at zero. Violation of the centering condition results in a warning. Default is True.

Returns:
ndarray of shape (…, n_components, …)

Inverse RCLR-transformed compositions. NaN values in the input become zeros, and each composition sums to 1.

See also

rclr
clr_inv

Notes

Note

This function supports the Python array API standard. Compatible array backends:

Backend

CPU

GPU

NumPy

n/a

CuPy

n/a

PyTorch

JAX

Dask

n/a

RCLR converts both zeros and missing (NaN) values to NaN. Therefore, the original distinction between zeros and missing values cannot be recovered from inverse RCLR transformation. This function considers all NaNs as unobserved zero components.

As with CLR, RCLR is scale invariant. Therefore rclr_inv(rclr(mat)) recovers closure(mat), rather than the original scale of mat.

Examples

>>> import numpy as np
>>> from skbio.stats.composition import rclr_inv
>>> x = np.array([-0.3, np.nan, 0.2, 0.1])
>>> rclr_inv(x)
array([ 0.24151404,  0.        ,  0.39818934,  0.36029662])