stan-dev / posterior

The posterior R package
https://mc-stan.org/posterior/
Other
167 stars 24 forks source link

Add alias ess_mean() for ess_basic() #378

Closed avehtari closed 1 month ago

avehtari commented 1 month ago

I'm using posterior in teaching, and I realized it would be useful to have ess_mean() as an alias for ess_basic() as we also have ess_quantile(), ess_sd(), mcse_mean(), mcse_quantile(), and mcse_sd()

n-kall commented 1 month ago

It seems ess_mean() exists but currently calls .ess(.split_chains(x)). So it is not completely an alias of ess_basic() as it doesn't allow for split = FALSE

paul-buerkner commented 1 month ago

Does the doc fix, already fix the issue you had Aki?

avehtari commented 1 month ago

Doc fix is not enough if ess_mean() has different behavior from ess_basic(). I assume ess_mean() is not currently exposed, and thus if an internal function is needed which calls .ess(.split_chains(x)) that could be calles .ess_mean() and then make the alias as I suggested.

n-kall commented 1 month ago

Currently ess_mean is exposed though, see here

paul-buerkner commented 1 month ago

I think the issue was just that the doc of ess_mean was wrong so the function wasn't visible properly. The different behavior is because we want ess_basic to be able to turn off split_chains but for the other ess functions such as ess_mean, ess_sd, we always want to split chains.

I also discovered some other places where ess_mean was not mentioned in the doc. I will fix them.

avehtari commented 1 month ago

Ah, so this actually works, and alias is not needed

> draws |> summarise_draws(mean, sd, ess_mean, ess_basic, mcse_mean)
# A tibble: 5 × 6
  variable     mean    sd ess_mean ess_basic mcse_mean
  <chr>       <dbl> <dbl>    <dbl>     <dbl>     <dbl>
1 b_Intercept  0.76  0.64  1586.54   1586.54      0.02
2 Intercept    0.76  0.64  1586.54   1586.54      0.02
3 lprior      -1.59  0.27  1535.70   1535.70      0.01
4 lp__        -8.14  0.73  1718.75   1718.75      0.02
5 theta        0.67  0.13  1632.43   1632.43      0.00

I'll update my course slides to use ess_mean

paul-buerkner commented 1 month ago

Great! Updated some more of the docs. Will close this issue now since things seem to be now working and documented as expected.