Description
As part of a notebook for pymc (pymc-devs/pymc-examples#241, seen here) to support the addition of the Generalized Extreme Value distribution (pymc-devs/pymc#5085), I had a few complexities processing results with the current API.
I'm raising this issue here to see if there is appetite for a PR along the proposed lines here.
- This code snippet is used to compare a posterior result with the maximum likelihood estimate from the reference book:
_, vals = az.sel_utils.xarray_to_ndarray(trace["posterior"], var_names=["μ", "σ", "ξ"])
mle = [az.plots.plot_utils.calculate_point_estimate("mode", val) for val in vals]
As can be seen, this uses/abuses a few back-end Arviz functions. It would seem better to have a cleaner API to access the point estimates that can be obtained in the hdi plots parameters point_estimate
argument, such as mean
, mode
, median
. Something like: az.get_point_estimate(point_estimate='mode', var_names=["μ", "σ", "ξ"])
.
- Getting the variance-covariance matrix of the estimates requires a pandas interface:
trace["posterior"].drop_vars("z_p").to_dataframe().cov().round(6)
Again, this is a bit non-bayesian, but is useful for comparison with results from other sources. So something like: az.get_var_covar(var_names=["μ", "σ", "ξ"])
.
-
Again, looking at that
InferenceData
accessor to the xarraydrop_vars
, it would be neat if there was a comparableget_vars
which returned the results for the selected variables - this functionality is already built-in of course, as is used through the arguments to many of the plot functions. But something directly like:trace["posterior"].get_vars(["μ", "σ", "ξ"])
would be helpful. -
More minor: It seems that to examine the prior predictive checks, we should now use the
plot_posterior
function. I suspect aplot_prior
wrapper would be more logical and more readable code.
az.plot_posterior(
prior_pc, group="prior", var_names=["μ", "σ", "ξ"], hdi_prob="hide", point_estimate=None
);