Skip to content

theil_within_group

Compute the within group Theil index.

Parameters:

Name Type Description Default
x Sequence

The input value-vector. Shape (n, )

required
partition Sequence

The groups for each x value. Shape (n, ).

required

Returns:

Name Type Description
float float

The computed within group Theil index.

Source code in src/histolytics/spatial_agg/diversity.py
def theil_within_group(x: Sequence, partition: Sequence) -> float:
    """Compute the within group Theil index.

    Parameters:
        x (Sequence):
            The input value-vector. Shape (n, )
        partition (Sequence):
            The groups for each x value. Shape (n, ).

    Returns:
        float:
            The computed within group Theil index.
    """
    theil = theil_index(x)
    theil_bg = theil_between_group(x, partition)

    return float(theil - theil_bg)