arviz.waic(data, pointwise=None, var_name=None, scale=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 and here

data: obj

Any object that can be converted to an az.InferenceData object. Refer to documentation of az.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.

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

True if posterior variance of the log predictive densities exceeds 0.4

waic_i: xarray.DataArray with the pointwise predictive accuracy, only if pointwise=True
waic_scale: scale of the reported waic results

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


Calculate WAIC of a model:

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

          Estimate       SE
elpd_waic   -30.76     1.42
p_waic        0.90        -

Calculate WAIC of a model and return the pointwise values:

In [2]: data_waic = az.waic(data, pointwise=True)
   ...: data_waic.waic_i
<xarray.DataArray 'waic_i' (school: 8)>
array([-4.91534201, -3.41568055, -3.85543363, -3.46533901, -3.40121364,
       -3.4765078 , -4.27523419, -3.95322615])
  * school   (school) object 'Choate' 'Deerfield' ... "St. Paul's" 'Mt. Hermon'