InversePropensityWeighting.weighted_percentile#

InversePropensityWeighting.weighted_percentile(data, weights, perc)[source]#

Compute a weighted percentile of the data.

Sorts data and weights together, builds a weighted empirical CDF, and linearly interpolates to find the value at the requested percentile.

Parameters:
  • data (ndarray) – One-dimensional array of data values.

  • weights (ndarray) – Non-negative weights corresponding to each element of data.

  • perc (float) – Desired percentile expressed as a fraction in [0, 1] (e.g., 0.5 for the median).

Returns:

The interpolated data value at the given weighted percentile.

Return type:

float

Raises:

ValueError – If perc is not between 0 and 1.