arviz-devs / arviz-stats

Statistical computation and diagnostics for ArviZ.
https://arviz-stats.readthedocs.io
Apache License 2.0
2 stars 1 forks source link

Add khat and ps_min_ss #20

Closed aloctavodia closed 2 months ago

aloctavodia commented 3 months ago

This is just a placeholder, the goal is to eventually have a function to compute the min_ss as discussed here. The original implementation is here. There a lot of other functions implemented (also discussed in the vignette from the first link), I think we don't want those other functions, at least not now.

I checked that I am getting the same result as in the vignette (to be sure I installed the Posterior package, I got the value of mu and converted it into a DataArray)

mu <- extract_variable_matrix)(example_draws(), "mu")
pareto_diags(mu)
#> $khat
#> [1] 0.1979001
#> 
#> $min_ss
#> [1] 17.6493

This is an example of how to run the function, first compute the k-hat and then the min_ss

sc = az.load_arviz_data("centered_eight")

mu = sc.posterior["mu"]
k = pareto_khat(mu)
ps_min_ss(k)

Notice that a lot of this code overlaps with the code necessary to compute the pareto smoothing part of the PSIS-CV-LOO method (notice the "log_weights" argument in the code in this PR). So eventually we will need to use some of this code for LOO too.


📚 Documentation preview 📚: https://arviz-stats--20.org.readthedocs.build/en/20/