arviz_stats.qds#
- arviz_stats.qds(data, dim=None, group='posterior', var_names=None, filter_vars=None, coords=None, nquantiles=100, binwidth=None, dotsize=1, stackratio=1, **kwargs)[source]#
Compute the marginal quantile dots.
For details see [1] and check the EABM chapter on Visualization of Random Variables with ArviZ.
- Parameters:
- dataarray_like,
xarray.DataArray
,xarray.Dataset
,xarray.DataTree
,DataArrayGroupBy
,DatasetGroupBy
, or idata-like Input data. It will have different pre-processing applied to it depending on its type:
array-like: call array layer within
arviz-stats
.xarray object: apply dimension aware function to all relevant subsets
others: passed to
arviz_base.convert_to_dataset
then treated asxarray.Dataset
. This option is discouraged due to needing this conversion which is completely automated and will be needed again in future executions or similar functions.It is recommended to first perform the conversion manually and then call
arviz_stats.kde
. This allows controlling the conversion step and inspecting its results.
- dimsequence of
hashable
, optional Dimensions to be reduced when computing the quantile dots Default
rcParams["data.sample_dims"]
.- group
hashable
, default “posterior” Group on which to compute the quantile dots
- var_names
str
orlist
ofstr
, optional Names of the variables for which the quantile dots should be computed.
- filter_vars{
None
, “like”, “regex”}, defaultNone
- coords
dict
, optional Dictionary of dimension/index names to coordinate values defining a subset of the data for which to perform the computation.
- binwidth
float
, optional Width of the bin for the dots.
- dotsize
float
, default 1 The size of the dots relative to the bin width. The default makes dots be just about as wide as the bin width.
- stackratio
float
, default 1 The distance between the center of the dots in the same stack relative to the bin height. The default makes dots in the same stack just touch each other.
- **kwargs
any
, optional Forwarded to the array or dataarray interface for quantile dots.
- dataarray_like,
- Returns:
ndarray
,xarray.DataArray
,xarray.Dataset
,xarray.DataTree
Requested QDs of the provided input. The xarray objects will have a
qds_dim
dimension and aplot_axis
dimension with coordinates “x”, and “y”.
See also
arviz_stats.ecdf
,arviz_stats.histogram
,arviz_stats.kde
Alternative visual summaries for marginal distributions
arviz_plots.plot_dist
References
[1]Kay M, Kola T, Hullman JR, and Munson SA. When (ish) is My Bus?: User-centered Visualizations of Uncertainty in Everyday, Mobile Predictive Systems. In Proceedings of the 2016 CHI Conference Association for Computing Machinery. 2016. https://doi.org/10.1145/2858036.2858558
Examples
Calculate the QDs of a Normal random variable:
In [1]: import arviz_stats as azs ...: import numpy as np ...: data = np.random.default_rng().normal(size=2000) ...: azs.qds(data) ...: Out[1]: (array([-2.35654682, -1.98214005, -1.98214005, -1.62626319, -1.62626319, -1.62626319, -1.38161377, -1.38161377, -1.38161377, -1.38161377, -1.12575565, -1.12575565, -1.12575565, -1.12575565, -1.12575565, -0.88593784, -0.88593784, -0.88593784, -0.88593784, -0.88593784, -0.88593784, -0.65648948, -0.65648948, -0.65648948, -0.65648948, -0.65648948, -0.65648948, -0.65648948, -0.4343695 , -0.4343695 , -0.4343695 , -0.4343695 , -0.4343695 , -0.4343695 , -0.4343695 , -0.4343695 , -0.22670758, -0.22670758, -0.22670758, -0.22670758, -0.22670758, -0.22670758, -0.22670758, -0.22670758, -0.01546457, -0.01546457, -0.01546457, -0.01546457, -0.01546457, -0.01546457, -0.01546457, -0.01546457, -0.01546457, 0.19720502, 0.19720502, 0.19720502, 0.19720502, 0.19720502, 0.19720502, 0.19720502, 0.19720502, 0.40432871, 0.40432871, 0.40432871, 0.40432871, 0.40432871, 0.40432871, 0.40432871, 0.40432871, 0.61181511, 0.61181511, 0.61181511, 0.61181511, 0.61181511, 0.61181511, 0.61181511, 0.82616068, 0.82616068, 0.82616068, 0.82616068, 0.82616068, 0.82616068, 1.0478598 , 1.0478598 , 1.0478598 , 1.0478598 , 1.0478598 , 1.27581663, 1.27581663, 1.27581663, 1.27581663, 1.5041899 , 1.5041899 , 1.5041899 , 1.76303412, 1.76303412, 1.76303412, 2.0909525 , 2.0909525 , 2.63373323]), array([0.09954169, 0.09954169, 0.29862506, 0.09954169, 0.29862506, 0.49770843, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 1.29404191, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 1.29404191, 1.49312528, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 1.29404191, 1.49312528, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 1.29404191, 1.49312528, 1.69220865, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 1.29404191, 1.49312528, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 1.29404191, 1.49312528, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 1.29404191, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 1.09495854, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.89587517, 0.09954169, 0.29862506, 0.49770843, 0.6967918 , 0.09954169, 0.29862506, 0.49770843, 0.09954169, 0.29862506, 0.49770843, 0.09954169, 0.29862506, 0.09954169]), array(0.09954169))
Calculate the QDs for specific variables:
In [2]: import arviz_base as azb ...: dt = azb.load_arviz_data("centered_eight") ...: azs.qds(dt, var_names=["mu", "theta"]) ...: Out[2]: <xarray.DataTree 'posterior'> Group: /posterior Dimensions: (plot_axis: 2, qd_dim: 100, school: 8) Coordinates: * plot_axis (plot_axis) <U1 8B 'x' 'y' radius_mu float64 8B 0.3682 * school (school) <U16 512B 'Choate' 'Deerfield' ... 'Mt. Hermon' radius_theta (school) float64 64B 0.7168 0.5463 0.6846 ... 0.5679 0.7148 Dimensions without coordinates: qd_dim Data variables: mu (plot_axis, qd_dim) float64 2kB -5.17 -3.397 ... 0.3682 0.3682 theta (plot_axis, school, qd_dim) float64 13kB -7.762 ... 0.7148
Calculate the QDs also over the school dimension (for variables where present):
In [3]: azs.qds(dt, dim=["chain", "draw", "school"]) Out[3]: <xarray.DataTree 'posterior'> Group: /posterior Dimensions: (plot_axis: 2, qd_dim: 100) Coordinates: * plot_axis (plot_axis) <U1 8B 'x' 'y' radius_mu float64 8B 0.3682 radius_theta float64 8B 0.6464 radius_tau float64 8B 0.3271 Dimensions without coordinates: qd_dim Data variables: mu (plot_axis, qd_dim) float64 2kB -5.17 -3.397 ... 0.3682 0.3682 theta (plot_axis, qd_dim) float64 2kB -11.06 -7.544 ... 0.6464 tau (plot_axis, qd_dim) float64 2kB 1.199 1.199 ... 0.3271 0.3271