# Cmdstan\_summary() as a matrix

**URL:** <https://discourse.mc-stan.org/t/cmdstan-summary-as-a-matrix/28752>\
**Category:** CmdStan\
**Tags:** cmdstanr\
**Created:** [September 6, 2022, 2:19pm UTC](https://discourse.mc-stan.org/t/cmdstan-summary-as-a-matrix/28752 "2022-09-06T14:19:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreasM](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@AndreasM](https://discourse.mc-stan.org/u/AndreasM)\
**Post date:** [September 6, 2022, 2:19pm UTC](https://discourse.mc-stan.org/t/cmdstan-summary-as-a-matrix/28752/1 "2022-09-06T14:19:19Z")

</div>

Hi!

I am using cmdstan in R to draw sample from a posterior distribution. Once the sampling is completed, I would like to use some of the output of cmdstan\_summary() for further process (i.e. to compute the MCSE to StdDev ratio). However, I cannot isolate the “table” of the cmdstan\_summary(). Is there any was I could save only that as a matrix or any?

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [September 6, 2022, 6:05pm UTC](https://discourse.mc-stan.org/t/cmdstan-summary-as-a-matrix/28752/2 "2022-09-06T18:05:43Z")

</div>

See [Compute a summary table of estimates and diagnostics — fit-method-summary • cmdstanr](https://mc-stan.org/cmdstanr/reference/fit-method-summary.html)

---

<div class="post-metadata">

**Author:** ![AndreasM](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@AndreasM](https://discourse.mc-stan.org/u/AndreasM)\
**Post date:** [September 7, 2022, 1:28pm UTC](https://discourse.mc-stan.org/t/cmdstan-summary-as-a-matrix/28752/3 "2022-09-07T13:28:14Z")

</div>

Thanks, avatar! Unfortunately, this is not what I am looking for. The summary()/print() extensions only return some summary statistics, while the cmdstan\_summary() offers more information - specifically I wish to isolate the MCSE.

Ideally, I am interested to obtain the output of cmdstan\_summary() in a matrix form, where rows are the variables, and columns are the statistics. This would be useful to use these for further analysis, or pass them into tables for presentation, etc.

Are you aware of any such ability of stan?

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [September 7, 2022, 2:40pm UTC](https://discourse.mc-stan.org/t/cmdstan-summary-as-a-matrix/28752/4 "2022-09-07T14:40:50Z")

</div>

> [@AndreasM](#):
>
> The summary()/print() extensions only return some summary statistics, while the cmdstan\_summary() offers more information - specifically I wish to isolate the MCSE.

I guess you missed that documentation of `summary()` states that it uses `posterior::summarise_draws()` which supports all possible diagnostics including MCSE. See [Summaries of draws objects — draws\_summary • posterior](https://mc-stan.org/posterior/reference/draws_summary.html) and [List of available convergence diagnostics — diagnostics • posterior](https://mc-stan.org/posterior/reference/diagnostics.html). See, for example, case study [Bayesian workflow book - Digits](https://avehtari.github.io/casestudies/Digits/digits.html) which illustrates use of `summarise_draws` to display tables of MCSEs.

---

<div class="post-metadata">

**Author:** ![AndreasM](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@AndreasM](https://discourse.mc-stan.org/u/AndreasM)\
**Post date:** [September 8, 2022, 3:42pm UTC](https://discourse.mc-stan.org/t/cmdstan-summary-as-a-matrix/28752/5 "2022-09-08T15:42:08Z")

</div>

Thanks, @avehtari!

I dived into the files and find a way to get what I was looking for. I will post the solution here, just for other if needed:

data.frame(summarise\_draws(sample\_draws,mean, mcse = mcse\_mean, sd, median,  
quantile2,rhat,ess\_basic,ess\_bulk,ess\_tail))

Looking on the links of summary statistics and/or convergence diagnostics, one could edit what stats to include:

> **[Summaries of draws objects — draws\_summary](https://mc-stan.org/posterior/reference/draws_summary.html)**
>
> The summarise\_draws() (and summarize\_draws()) methods provide a quick way
> to get a table of summary statistics and diagnostics. These methods will
> convert an object to a draws object if it isn't already. For convenience, a
> summary() method for draws...

> **[List of available convergence diagnostics — diagnostics](https://mc-stan.org/posterior/reference/diagnostics.html)**
>
> A list of available diagnostics and links to their individual help pages.

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [September 8, 2022, 4:33pm UTC](https://discourse.mc-stan.org/t/cmdstan-summary-as-a-matrix/28752/6 "2022-09-08T16:33:50Z")

</div>

Great that you find what you need!

> [@AndreasM](#):
>
> data.frame(summarise\_draws(sample\_draws,mean, mcse = mcse\_mean, sd, median,  
> quantile2,rhat,ess\_basic,ess\_bulk,ess\_tail))

Adding, that those who are happy with the default tibble output (which is a data.frame with improved behaviour) can drop the data.frame part (but I understand if you prefer base data.frame)
