# Fast cmdstanr summary function

**URL:** <https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940>\
**Category:** Modeling\
**Tags:** cmdstanr\
**Created:** [July 20, 2024, 11:18pm UTC](https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940 "2024-07-20T23:18:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewGhazi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewghazi/32/18855_2.png) [@andrewGhazi](https://discourse.mc-stan.org/u/andrewGhazi)\
**Post date:** [July 20, 2024, 11:18pm UTC](https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940/1 "2024-07-20T23:18:27Z")

</div>

Hi everyone. I wrote a small R library for quickly computing posterior summaries of `draws_df` objects. It’s available at the link below. I’ve seen that there’s [been some discussion](https://github.com/stan-dev/posterior/issues/284) of [speeding up summaries](https://github.com/stan-dev/posterior/issues/98) before, but this goes beyond speeding up the mean/median/sd and also improves the speed of computing the convergence metrics. My function is not as generic / deeply-tested as `posterior::summarise_draws()`, but it gives me a good performance boost for my purposes. Maybe someone will find it useful, just thought I’d share.

Blog post with a bit more detail: [Fast cmdstanr summary function – andrewghazi.github.io](https://andrewghazi.github.io/posts/fsummary/fsummary.html)  
Github repo: [GitHub - andrewGhazi/fsummary: Fast cmdstanr summaries](https://github.com/andrewGhazi/fsummary)

 ![unnamed-chunk-1-1](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/3X/1/4/142db7e8ff9f7cc845f889de86de955df399d7bd.png)

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [July 22, 2024, 8:14pm UTC](https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940/2 "2024-07-22T20:14:32Z")

</div>

Cool, thanks for sharing this!

---

<div class="post-metadata">

**Author:** ![huffyhenry](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/huffyhenry/32/781_2.png) [@huffyhenry](https://discourse.mc-stan.org/u/huffyhenry)\
**Post date:** [July 23, 2024, 9:25am UTC](https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940/3 "2024-07-23T09:25:20Z")

</div>

Very cool! I had the same issue and solved it with a [wrapper](https://github.com/huffyhenry/Stanislaw) of the `stansummary` command-line utility.

---

<div class="post-metadata">

**Author:** ![andrewGhazi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewghazi/32/18855_2.png) [@andrewGhazi](https://discourse.mc-stan.org/u/andrewGhazi)\
**Post date:** [July 23, 2024, 3:15pm UTC](https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940/4 "2024-07-23T15:15:41Z")

</div>

Ah interesting, I didn’t know about this. I’ll have to check how it compares.

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [July 24, 2024, 1:03pm UTC](https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940/5 "2024-07-24T13:03:28Z")

</div>

> [@huffyhenry](#):
>
> Very cool! I had the same issue and solved it with a [wrapper](https://github.com/huffyhenry/Stanislaw) of the `stansummary` command-line utility.

The `stansummary` utility in CmdStan is using an older version of Rhat, not the rank-normalized computations introduced in this [[1903.08008] Rank-normalization, folding, and localization: An improved $\widehat{R}$ for assessing convergence of MCMC](https://arxiv.org/abs/1903.08008) paper. I’m working on a refactor that will correct this; also improve performance. Like all refactors, easier said than done.

---

<div class="post-metadata">

**Author:** ![huffyhenry](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/huffyhenry/32/781_2.png) [@huffyhenry](https://discourse.mc-stan.org/u/huffyhenry)\
**Post date:** [July 24, 2024, 1:16pm UTC](https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940/6 "2024-07-24T13:16:18Z")

</div>

> [@mitzimorris](#):
>
> The `stansummary` utility in CmdStan is using an older version of Rhat

I wondered about this! Thanks for confirming. Compared to `posterior`, `stansummary` does not provide tail ESS either. Is this something we can hope for too?

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [July 24, 2024, 4:17pm UTC](https://discourse.mc-stan.org/t/fast-cmdstanr-summary-function/35940/7 "2024-07-24T16:17:34Z")

</div>

> [@huffyhenry](#):
>
> Compared to `posterior`, `stansummary` does not provide tail ESS either. Is this something we can hope for too?

yes. we were lucky to pick up a new Stan dev who implemented the rank-normalization needed to do the bulk, tail Rhat, it’s just a matter of using that for ESS as well. as I said, WIP.
