Skip to content

Pivot logratio transform

plr_transform(df)

Perform a pivot logratio transformation on the dataframe, returning the full set of transforms.

Parameters:

Name Type Description Default
df DataFrame

A dataframe of shape [N, D] of compositional data.

required

Returns:

Type Description
DataFrame

A dataframe of shape [N, D-1] containing the set of PLR transformed data.

Raises:

Type Description
InvalidColumnException

The data contains one or more zeros.

InvalidCompositionException

Data is not normalized to the expected value.

NumericValueSignException

Data contains zeros or negative values.

Source code in eis_toolkit/transformations/coda/plr.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@beartype
def plr_transform(df: pd.DataFrame) -> pd.DataFrame:
    """
    Perform a pivot logratio transformation on the dataframe, returning the full set of transforms.

    Args:
        df: A dataframe of shape [N, D] of compositional data.

    Returns:
        A dataframe of shape [N, D-1] containing the set of PLR transformed data.

    Raises:
        InvalidColumnException: The data contains one or more zeros.
        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(_plr_transform(df))

single_plr_transform(df, column)

Perform a pivot logratio transformation on the selected column.

Pivot logratio is a special case of ILR, where the numerator in the ratio is always a single part and the denominator all of the parts to the right in the ordered list of parts.

Column order matters.

Parameters:

Name Type Description Default
df DataFrame

A dataframe of shape [N, D] of compositional data.

required
column str

The name of the numerator column to use for the transformation.

required

Returns:

Type Description
Series

A series of length N containing the transforms.

Raises:

Type Description
InvalidColumnException

The input column isn't found in the dataframe, or there are no columns to the right of the given column.

InvalidCompositionException

Data is not normalized to the expected value.

NumericValueSignException

Data contains zeros or negative values.

Source code in eis_toolkit/transformations/coda/plr.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@beartype
def single_plr_transform(df: pd.DataFrame, column: str) -> pd.Series:
    """
    Perform a pivot logratio transformation on the selected column.

    Pivot logratio is a special case of ILR, where the numerator in the ratio is always a single
    part and the denominator all of the parts to the right in the ordered list of parts.

    Column order matters.

    Args:
        df: A dataframe of shape [N, D] of compositional data.
        column: The name of the numerator column to use for the transformation.

    Returns:
        A series of length N containing the transforms.

    Raises:
        InvalidColumnException: The input column isn't found in the dataframe, or there are no columns
            to the right of the given column.
        InvalidCompositionException: Data is not normalized to the expected value.
        NumericValueSignException: Data contains zeros or negative values.
    """
    check_in_simplex_sample_space(df)

    if column not in df.columns:
        raise InvalidColumnException(f"The column {column} was not found in the dataframe.")

    idx = df.columns.get_loc(column)

    if idx == len(df.columns) - 1:
        raise InvalidColumnException()

    return _single_plr_transform(df, column)