# arviz.loo_pit¶

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.

Parameters
idata: InferenceData
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 related kwargs passed to `wrap_xarray_ufunc()`.

Returns
loo_pit: array or DataArray

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

`plot_loo_pit`

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

`loo`

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

`plot_elpd`

Plot pointwise elpd differences between two or more models.

`plot_khat`

Plot Pareto tail indices for diagnosing convergence.

Examples

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

```In : import arviz as az
...: az.loo_pit(idata=data, y="obs")
...:
Out:
array([0.93709089, 0.64299662, 0.35337357, 0.60399173, 0.30656125,
0.38855003, 0.91081225, 0.65456656])
```

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 : T = data.observed_data.obs - data.posterior.mu.median(dim=("chain", "draw"))
...: T_hat = data.posterior_predictive.obs - data.posterior.mu
...: T_hat = T_hat.stack(__sample__=("chain", "draw"))
...: az.loo_pit(idata=data, y=T**2, y_hat=T_hat**2)
...:
Out:
<xarray.DataArray (school: 8)>
array([0.87402093, 0.30510478, 0.29976597, 0.21659434, 0.37194385,
0.20309587, 0.82479374, 0.33979512])
Coordinates:
* school   (school) object 'Choate' 'Deerfield' ... "St. Paul's" 'Mt. Hermon'
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.5292599,"math_prob":0.95281225,"size":2285,"snap":"2021-43-2021-49","text_gpt3_token_len":683,"char_repetition_ratio":0.09601052,"word_repetition_ratio":0.055172414,"special_character_ratio":0.31684902,"punctuation_ratio":0.26923078,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9923633,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-07T17:24:14Z\",\"WARC-Record-ID\":\"<urn:uuid:99281e81-ac97-4976-b861-7c756234d8cd>\",\"Content-Length\":\"66289\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7271a0a0-d479-4067-a697-891d23667ad5>\",\"WARC-Concurrent-To\":\"<urn:uuid:9b6229a6-e6e5-46cc-964a-870c4580a1ee>\",\"WARC-IP-Address\":\"185.199.109.153\",\"WARC-Target-URI\":\"https://arviz-devs.github.io/arviz/api/generated/arviz.loo_pit.html\",\"WARC-Payload-Digest\":\"sha1:CRHN6GXVQRGBXDFENGFM4XASAQ3PDRSF\",\"WARC-Block-Digest\":\"sha1:YKTULUVLAFQB2RS455ZTGHK63JPU5SEZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363405.77_warc_CC-MAIN-20211207170825-20211207200825-00222.warc.gz\"}"}