# xarray.computation.weighted.DataArrayWeighted.quantile

#### DataArrayWeighted.quantile(q, , dim=None, keep_attrs=None, skipna=True)[[source]](https://github.com/pydata/xarray/blob/main/xarray/computation/weighted.py#L518-L528)

Apply a weighted `quantile` to this Dataset’s data along some dimension(s).

Weights are interpreted as *sampling weights* (or probability weights) and
describe how a sample is scaled to the whole population <sup>[1](#id4)</sup>. There are
other possible interpretations for weights, *precision weights* describing the
precision of observations, or *frequency weights* counting the number of identical
observations, however, they are not implemented here.

For compatibility with NumPy’s non-weighted `quantile` (which is used by
`DataArray.quantile` and `Dataset.quantile`), the only interpolation
method supported by this weighted version corresponds to the default “linear”
option of `numpy.quantile`. This is “Type 7” option, described in Hyndman
and Fan (1996) <sup>[2](#id5)</sup>. The implementation is largely inspired by a blog post
from A. Akinshin’s (2023) <sup>[3](#id6)</sup>.

* **Parameters:**
  * **q** ([`float`](https://docs.python.org/3/builtins/functions.html#float) or [sequence](https://docs.python.org/3/glossary.html#term-sequence) of [`float`](https://docs.python.org/3/builtins/functions.html#float)) – Quantile to compute, which must be between 0 and 1 inclusive.
  * **dim** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or [sequence](https://docs.python.org/3/glossary.html#term-sequence) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str), *optional*) – Dimension(s) over which to apply the weighted `quantile`.
  * **skipna** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *optional*) – If True, skip missing values (as marked by NaN). By default, only
    skips missing values for float dtypes; other dtypes either do not
    have a sentinel missing value (int) or skipna=True has not been
    implemented (object, datetime64 or timedelta64).
  * **keep_attrs** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *optional*) – If True, the attributes (`attrs`) will be copied from the original
    object to the new one.  If False (default), the new object will be
    returned without attributes.
* **Returns:**
  **quantiles** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – New Dataset object with weighted `quantile` applied to its data and
  the indicated dimension(s) removed.

#### SEE ALSO
[`numpy.nanquantile`](https://numpy.org/doc/stable/reference/generated/numpy.nanquantile.html#numpy.nanquantile), [`pandas.Series.quantile`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.quantile.html#pandas.Series.quantile), `Dataset.quantile`, `DataArray.quantile`

### Notes

Returns NaN if the `weights` sum to 0.0 along the reduced
dimension(s).

### References

* <a id='id4'>**[1]**</a> [https://notstatschat.rbind.io/2020/08/04/weights-in-statistics/](https://notstatschat.rbind.io/2020/08/04/weights-in-statistics/)
* <a id='id5'>**[2]**</a> Hyndman, R. J. & Fan, Y. (1996). Sample Quantiles in Statistical Packages. The American Statistician, 50(4), 361–365. [https://doi.org/10.2307/2684934](https://doi.org/10.2307/2684934)
* <a id='id6'>**[3]**</a> Akinshin, A. (2023) “Weighted quantile estimators” arXiv:2304.07265 [stat.ME] https://arxiv.org/abs/2304.07265
