arviz.waic#

arviz.waic(data, pointwise=None, var_name=None, scale=None, dask_kwargs=None)[source]#

Compute the widely applicable information criterion.

Estimates the expected log pointwise predictive density (elpd) using WAIC. Also calculates the WAIC’s standard error and the effective number of parameters. Read more theory here https://arxiv.org/abs/1507.04544 and here https://arxiv.org/abs/1004.2316

Parameters:
data: obj

Any object that can be converted to an arviz.InferenceData object. Refer to documentation of arviz.convert_to_inference_data() for details.

pointwise: bool

If True the pointwise predictive accuracy will be returned. Defaults to stats.ic_pointwise rcParam.

var_namestr, optional

The name of the variable in log_likelihood groups storing the pointwise log likelihood data to use for waic computation.

scale: str

Output scale for WAIC. Available options are:

  • log : (default) log-score

  • negative_log : -1 * log-score

  • deviance : -2 * log-score

A higher log-score (or a lower deviance or negative log_score) indicates a model with better predictive accuracy.

dask_kwargsdict, optional

Dask related kwargs passed to wrap_xarray_ufunc().

Returns:
ELPDData object (inherits from pandas.Series) with the following row/attributes:
elpd_waic: approximated expected log pointwise predictive density (elpd)
se: standard error of the elpd
p_waic: effective number parameters
var_warn: bool

True if posterior variance of the log predictive densities exceeds 0.4

waic_i: DataArray with the pointwise predictive accuracy,

only if pointwise=True

scale: scale of the elpd

The returned object has a custom print method that overrides pd.Series method.

See also

loo

Compute Pareto-smoothed importance sampling leave-one-out cross-validation (PSIS-LOO-CV).

compare

Compare models based on PSIS-LOO-CV or WAIC.

plot_compare

Summary plot for model comparison.

Examples

Calculate WAIC of a model:

In [1]: import arviz as az
   ...: data = az.load_arviz_data("centered_eight")
   ...: az.waic(data)
   ...: 
Out[1]: 
Computed from 2000 posterior samples and 8 observations log-likelihood matrix.

          Estimate       SE
elpd_waic   -30.74     1.34
p_waic        0.91        -

Calculate WAIC of a model and return the pointwise values:

In [2]: data_waic = az.waic(data, pointwise=True)
   ...: data_waic.waic_i
   ...: 
Out[2]: 
<xarray.DataArray 'waic_i' (school: 8)> Size: 64B
array([-4.88183718, -3.41680906, -3.86581024, -3.46151052, -3.47061294,
       -3.49819736, -4.18890062, -3.95780072])
Coordinates:
  * school   (school) <U16 512B 'Choate' 'Deerfield' ... 'Mt. Hermon'