Skip to content

Pairwise logratio transform

pairwise_logratio(df, numerator_column, denominator_column)

Perform a pairwise logratio transformation on the given columns.

Parameters:

Name Type Description Default
df DataFrame

The dataframe containing the columns to use in the transformation.

required
numerator_column str

The name of the column to use as the numerator column.

required
denominator_column str

The name of the column to use as the denominator.

required

Returns:

Type Description
Series

A series containing the transformed values.

Raises:

Type Description
InvalidColumnException

One or both of the input columns are not found in the dataframe.

InvalidParameterValueException

The input columns contain at least one zero value.

Source code in eis_toolkit/transformations/coda/pairwise.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@beartype
def pairwise_logratio(df: pd.DataFrame, numerator_column: str, denominator_column: str) -> pd.Series:
    """
    Perform a pairwise logratio transformation on the given columns.

    Args:
        df: The dataframe containing the columns to use in the transformation.
        numerator_column: The name of the column to use as the numerator column.
        denominator_column: The name of the column to use as the denominator.

    Returns:
        A series containing the transformed values.

    Raises:
        InvalidColumnException: One or both of the input columns are not found in the dataframe.
        InvalidParameterValueException: The input columns contain at least one zero value.
    """
    if numerator_column not in df.columns or denominator_column not in df.columns:
        raise InvalidColumnException("At least one input column is not found in the dataframe.")

    if check_dataframe_contains_zeros(df[[numerator_column, denominator_column]]):
        raise InvalidParameterValueException("The input columns contain at least one zero value.")

    return _pairwise_logratio(df, numerator_column, denominator_column)

single_pairwise_logratio(numerator, denominator)

Perform a pairwise logratio transformation on the given values.

Parameters:

Name Type Description Default
numerator Number

The numerator in the ratio.

required
denominator Number

The denominator in the ratio.

required

Returns:

Type Description
float64

The transformed value.

Raises:

Type Description
InvalidParameterValueException

One or both input values are zero.

Source code in eis_toolkit/transformations/coda/pairwise.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@beartype
def single_pairwise_logratio(numerator: Number, denominator: Number) -> np.float64:
    """
    Perform a pairwise logratio transformation on the given values.

    Args:
        numerator: The numerator in the ratio.
        denominator: The denominator in the ratio.

    Returns:
        The transformed value.

    Raises:
        InvalidParameterValueException: One or both input values are zero.
    """
    if numerator == 0 or denominator == 0:
        raise InvalidParameterValueException("Input values cannot be zero.")

    return _single_pairwise_logratio(numerator, denominator)