arviz.loo_pit(idata=None, *, y=None, y_hat=None, log_weights=None)[source]#

Compute leave one out (PSIS-LOO) probability integral transform (PIT) values.

idata: InferenceData

arviz.InferenceData object.

y: array, DataArray or str

Observed data. If str, idata must be present and contain the observed data group

y_hat: array, DataArray or str

Posterior predictive samples for y. It must have the same shape as y plus an extra dimension at the end of size n_samples (chains and draws stacked). If str or None, idata must contain the posterior predictive group. If None, y_hat is taken equal to y, thus, y must be str too.

log_weights: array or DataArray

Smoothed log_weights. It must have the same shape as y_hat

dask_kwargsdict, optional

Dask related kwargs passed to wrap_xarray_ufunc().

loo_pit: array or DataArray

Value of the LOO-PIT at each observed data point.

See also


Plot Leave-One-Out probability integral transformation (PIT) predictive checks.


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


Plot pointwise elpd differences between two or more models.


Plot Pareto tail indices for diagnosing convergence.


Calculate LOO-PIT values using as test quantity the observed values themselves.

In [1]: import arviz as az
   ...: data = az.load_arviz_data("centered_eight")
   ...: az.loo_pit(idata=data, y="obs")
array([0.94353257, 0.63801204, 0.31667474, 0.58227422, 0.29533466,
       0.40245644, 0.90248636, 0.65535458])

Calculate LOO-PIT values using as test quantity the square of the difference between each observation and mu. Both y and y_hat inputs will be array-like, but idata will still be passed in order to calculate the log_weights from there.

In [2]: T = data.observed_data.obs -"chain", "draw"))
   ...: T_hat = data.posterior_predictive.obs -
   ...: T_hat = T_hat.stack(__sample__=("chain", "draw"))
   ...: az.loo_pit(idata=data, y=T**2, y_hat=T_hat**2)
<xarray.DataArray (school: 8)>
array([0.87363611, 0.24371712, 0.3574756 , 0.14990395, 0.43520598,
       0.22133526, 0.77501908, 0.29666433])
  * school   (school) object 'Choate' 'Deerfield' ... "St. Paul's" 'Mt. Hermon'