arviz_stats.eti

Contents

arviz_stats.eti#

arviz_stats.eti(data, prob=None, dim=None, group='posterior', var_names=None, filter_vars=None, coords=None, method='linear', skipna=False, **kwargs)[source]#

Compute the equal tail interval (ETI) given a probability.

The ETI is constructed by dividing the remaining probability (e.g., 6% for a 94% interval) equally between the two tails of a distribution. Other names for ETI are central interval and quantile-based interval.

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 as xarray.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.eti. This allows controlling the conversion step and inspecting its results.

probfloat, optional

Probability for the credible interval. Defaults to rcParams["stats.ci_prob"]

dimsequence of hashable, optional

Dimensions to be reduced when computing the HDI. Default rcParams["data.sample_dims"].

grouphashable, default “posterior”

Group on which to compute the ETI.

var_namesstr or list of str, optional

Names of the variables for which the ETI should be computed.

filter_vars{None, “like”, “regex”}, default None
coordsdict, optional

Dictionary of dimension/index names to coordinate values defining a subset of the data for which to perform the computation.

methodstr, default “linear”

For other options see numpy.quantile.

skipnabool, default False

If true ignores nan values when computing the ETI.

**kwargsany, optional

Forwarded to the array or dataarray interface for ETI.

Returns:
ndarray, xarray.DataArray, xarray.Dataset, xarray.DataTree

Requested ETI of the provided input. It will have a ci_bound dimension with coordinate values “lower” and “upper” indicating the two extremes of the credible interval.

See also

arviz_stats.hdi

Calculate the highest density interval (HDI).

arviz_stats.summary

Calculate summary statistics and diagnostics.

Examples

Calculate the ETI 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.eti(data, 0.68)
   ...: 
Out[1]: array([-1.01457865,  0.91094192])

Calculate the ETI for specific variables:

In [2]: import arviz_base as azb
   ...: dt = azb.load_arviz_data("centered_eight")
   ...: azs.eti(dt, var_names=["mu", "theta"])
   ...: 
Out[2]: 
<xarray.DataTree 'posterior'>
Group: /posterior
    Dimensions:   (ci_bound: 2, school: 8)
    Coordinates:
      * ci_bound  (ci_bound) <U5 40B 'lower' 'upper'
      * school    (school) <U16 512B 'Choate' 'Deerfield' ... 'Mt. Hermon'
    Data variables:
        mu        (ci_bound) float64 16B -1.968 10.54
        theta     (school, ci_bound) float64 128B -3.511 19.09 ... -6.348 15.57

Calculate the ETI also over the school dimension (for variables where present):

In [3]: azs.eti(dt, dim=["chain","draw", "school"])
Out[3]: 
<xarray.DataTree 'posterior'>
Group: /posterior
    Dimensions:   (ci_bound: 2)
    Coordinates:
      * ci_bound  (ci_bound) <U5 40B 'lower' 'upper'
    Data variables:
        mu        (ci_bound) float64 16B -1.968 10.54
        theta     (ci_bound) float64 16B -5.342 15.31
        tau       (ci_bound) float64 16B 0.9274 11.8