View source: R/summarise_draws.R
summarise_draws.grouped_df | R Documentation |
grouped_df
objectsAn implementation of posterior::summarise_draws()
for grouped data frames
(dplyr::grouped_df
objects) such as returned by dplyr::group_by()
and
the various grouped-data-aware functions in tidybayes, such as spread_draws()
,
gather_draws()
, add_epred_draws()
, and add_predicted_draws()
.
This function provides a quick way to get a variety of summary statistics
and diagnostics on draws.
## S3 method for class 'grouped_df'
summarise_draws(.x, ...)
.x |
A grouped data frame ( |
... |
Name-value pairs of summary or diagnostic functions. The provided names will be used as the names of the columns in the result unless the function returns a named vector, in which case the latter names are used. The functions can be specified in any format supported by as_function(). See Examples. |
While posterior::summarise_draws()
can operate on tidy data frames of
draws in the posterior::draws_df()
format, that format does not support
grouping columns. This provides an implementation of summarise_draws()
that does support grouped data tables, essentially applying
posterior::summarise_draws()
to every sub-table of .x
implied by the
groups defined on the data frame.
See posterior::summarise_draws()
for
more details on the summary statistics and diagnostics you can use with this
function. If you just want point summaries and intervals (not diagnostics),
particularly for plotting, see point_interval()
, which returns long-format
data tables more suitable for that purpose (especially if you want to plot
multiple uncertainty levels).
A data frame (actually, a tibble) with all grouping
columns from .x
, a "variable"
column containing variable names from .x
,
and the remaining columns containing summary statistics and diagnostics.
Matthew Kay
posterior::summarise_draws()
, point_interval()
library(posterior)
library(dplyr)
d = posterior::example_draws()
# The default posterior::summarise_draws() summarises all variables without
# splitting out indices:
summarise_draws(d)
# The grouped_df implementation of summarise_draws() in tidybayes can handle
# output from spread_draws(), which is a grouped data table with the indices
# (here, `i`) left as columns:
d %>%
spread_draws(theta[i]) %>%
summarise_draws()
# Summary functions can also be provided, as in posterior::summarise_draws():
d %>%
spread_draws(theta[i]) %>%
summarise_draws(median, mad, rhat, ess_tail)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.