Last updated on Aug 22, 2025.

netsse.tools.misc_func.weighted_quantile#

netsse.tools.misc_func.weighted_quantile(x, q, w, a=0.5, b=0.5, axis=-1)#

Computes the q-th quantiles of weighted data.

The quantiles are computed along one of the axes of the input array x.

Parameters:
  • x (array_like) – Input data array for which the quantiles must be computed.

  • q (1d-array of shape (Nq,)) – Sequence of quantiles to compute, which must be between 0 and 1.

  • w (array_like) – Array of weights. The arrays x and w must be broadcastable.

  • a (floats, default 0.5) – User-defined constant used in the computation of the quantiles. The default is 0.5 to minimize biases (Rogers, 2003).

  • b (floats, default 0.5) – User-defined constant used in the computation of the quantiles. The default is 0.5 to minimize biases (Rogers, 2003).

  • axis (integer, default -1) – Axis of x along which the q-quantiles are computed.

Returns:

v – Values of the q-quantiles computed along the specified axis of the input array x with weights w.

Return type:

array_like

See also

weighted_std

Computes the weighted standard deviation of some data.

References

Rogers, J.W., 2003. Estimating the variance of percentiles using replicate weights, in: Proc. of the Joint Statistical Meetings, Survey Research Methods Section, American Statistical Association. pp. 3525–3532. URL: http://www.asasrms.org/Proceedings/y2003/Files/JSM2003-000742.pdf

Example

>>> v = weighted_quantile(x, q, w, a=0.5, b=0.5, axis=-1)