Skip to content

Centered logratio transform

clr_transform(df)

Perform a centered logratio transformation on the data.

Parameters:

Name Type Description Default
df DataFrame

A dataframe of compositional data.

required

Returns:

Type Description
DataFrame

A new dataframe containing the CLR transformed data.

Raises:

Type Description
InvalidCompositionException

Data is not normalized to the expected value.

NumericValueSignException

Data contains zeros or negative values.

Source code in eis_toolkit/transformations/coda/clr.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@beartype
def clr_transform(df: pd.DataFrame) -> pd.DataFrame:
    """
    Perform a centered logratio transformation on the data.

    Args:
        df: A dataframe of compositional data.

    Returns:
        A new dataframe containing the CLR transformed data.

    Raises:
        InvalidCompositionException: Data is not normalized to the expected value.
        NumericValueSignException: Data contains zeros or negative values.
    """
    check_in_simplex_sample_space(df)
    return rename_columns_by_pattern(_clr_transform(df))

inverse_clr(df, colnames=None, scale=1.0)

Perform the inverse transformation for a set of CLR transformed data.

Parameters:

Name Type Description Default
df DataFrame

A dataframe of CLR transformed compositional data.

required
colnames Optional[Sequence[str]]

List of column names to rename the columns to.

None
scale Number

The value to which each composition should be normalized. Eg., if the composition is expressed as percentages, scale=100.

1.0

Returns:

Type Description
DataFrame

A dataframe containing the inverse transformed data.

Raises:

Type Description
NumericValueSignException

The input scale value is zero or less.

Source code in eis_toolkit/transformations/coda/clr.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@beartype
def inverse_clr(df: pd.DataFrame, colnames: Optional[Sequence[str]] = None, scale: Number = 1.0) -> pd.DataFrame:
    """
    Perform the inverse transformation for a set of CLR transformed data.

    Args:
        df: A dataframe of CLR transformed compositional data.
        colnames: List of column names to rename the columns to.
        scale: The value to which each composition should be normalized. Eg., if the composition is expressed
            as percentages, scale=100.

    Returns:
        A dataframe containing the inverse transformed data.

    Raises:
        NumericValueSignException: The input scale value is zero or less.
    """
    if scale <= 0:
        raise NumericValueSignException("The scale value should be positive.")

    return _inverse_clr(df, colnames, scale)