arviz_stats.ess#
- arviz_stats.ess(data, sample_dims=None, group='posterior', var_names=None, filter_vars=None, coords=None, method='bulk', relative=False, prob=None, chain_axis=0, draw_axis=1)[source]#
Estimate the effective sample size (ess).
- 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
- sample_dimsiterable of
hashable, optional Dimensions to be considered sample dimensions and are to be reduced. Default
rcParams["data.sample_dims"].- group
hashable, default “posterior” Group on which to compute the ESS.
- var_names
strorlistofstr, optional Names of the variables for which the ess 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.
- method
str, default “bulk” Valid methods are:
“bulk”
“tail” # prob, optional
“quantile” # prob
“mean” (old ess)
“sd”
“median”
“mad” (mean absolute deviance)
“z_scale”
“folded”
“identity”
“local” # prob
- relativebool
Return relative ess
ress = ess / n- prob
float, ortupleoftwofloats, optional Probability value for “tail”, “quantile” or “local” ess functions.
- chain_axis, draw_axis
int, optional Integer indicators of the axis that correspond to the chain and the draw dimension. chain_axis can be
None.
- dataarray_like,
- Returns:
ndarray,xarray.DataArray,xarray.Dataset,xarray.DataTreeRequested ESS summary of the provided input
See also
arviz.rhatCompute estimate of rank normalized split R-hat for a set of traces.
arviz.mcseCalculate Markov Chain Standard Error statistic.
plot_essPlot quantile, local or evolution of effective sample sizes (ESS).
arviz.summaryCreate a data frame with summary statistics.
Examples
Calculate the effective_sample_size using the default arguments:
In [1]: from arviz_base import load_arviz_data ...: import arviz_stats as azs ...: data = load_arviz_data('non_centered_eight') ...: azs.ess(data) ...: Out[1]: <xarray.DataTree 'posterior'> Group: /posterior Dimensions: (school: 8) Coordinates: * school (school) <U16 512B 'Choate' 'Deerfield' ... 'Mt. Hermon' Data variables: mu float64 8B 2.115e+03 theta_t (school) float64 64B 2.25e+03 2.638e+03 ... 1.981e+03 2.42e+03 tau float64 8B 833.8 theta (school) float64 64B 2.196e+03 2.322e+03 ... 1.431e+03 2.188e+03
Calculate ess for a subset of the variables
In [2]: azs.ess(data, relative=True, var_names=["mu", "theta_t"]) Out[2]: <xarray.DataTree 'posterior'> Group: /posterior Dimensions: (school: 8) Coordinates: * school (school) <U16 512B 'Choate' 'Deerfield' ... 'Mt. Hermon' Data variables: mu float64 8B 1.057 theta_t (school) float64 64B 1.125 1.319 1.345 1.216 ... 1.186 0.9904 1.21
Calculate ess using the “tail” method, leaving the prob at its default value.
In [3]: azs.ess(data, method="tail") Out[3]: <xarray.DataTree 'posterior'> Group: /posterior Dimensions: (school: 8) Coordinates: * school (school) <U16 512B 'Choate' 'Deerfield' ... 'Mt. Hermon' Data variables: mu float64 8B 1.22e+03 theta_t (school) float64 64B 1.467e+03 1.513e+03 ... 1.391e+03 1.538e+03 tau float64 8B 712.3 theta (school) float64 64B 1.444e+03 1.499e+03 ... 1.63e+03 1.569e+03