Skip to content

Reduce MAD over sample_dims in summary median kinds - #496

Open
cristianchiriac wants to merge 1 commit into
arviz-devs:mainfrom
cristianchiriac:summary-mad-sample-dims
Open

cristianchiriac wants to merge 1 commit into
arviz-devs:mainfrom
cristianchiriac:summary-mad-sample-dims

Conversation

@cristianchiriac

Copy link
Copy Markdown

Fixes #492.

summary(kind="stats_median") and kind="all_median" computed the MAD with stats.median_abs_deviation(dataset, dims=("chain", "draw"), ...), while the median and the ETI next to it reduce over sample_dims. With sample_dims=["draw"], each chain got the MAD pooled over all chains. The MAD now uses dims=validate_dims(sample_dims), like the rest of the function.

Tests in tests/test_summary.py, using the dataset from the issue (2 chains × 4 draws):

  • test_summary_stats_median_reduces_mad_over_sample_dims with sample_dims="draw" and ["draw"]: median [1.5, 103.0] and MAD [1.0, 2.0]. Before the change, the MAD was [50.5, 50.5].
  • test_summary_median_kind_pools_mad_by_default: the default call still gives the pooled MAD [50.5].

all_median goes through the same line, but it can't run with sample_dims=["draw"] because the diagnostics (r_hat) need two dims, so the test uses stats_median.

ruff check and ruff format --check are clean. In tests/test_summary.py on my machine, test_summary_data_frame, test_rope_coords, test_ci_in_rope_default_ci_kind and test_summary_sd_uses_sample_std fail or error the same way with and without this change (missing test-xarray extras locally). Everything else passes.

summary(kind="stats_median" or "all_median") computed the MAD over a
hardcoded ("chain", "draw"), while the median and eti use sample_dims,
so with sample_dims=["draw"] it reported the pooled MAD for every chain.

Fixes arviz-devs#492

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

summary pools MAD across chains when sample_dims=['draw']

1 participant