Learn R Programming

tidybayes (version 3.0.2)

gather_emmeans_draws: Extract a tidy data frame of draws of posterior distributions of "estimated marginal means" (emmeans/lsmeans) from a Bayesian model fit.

Description

Extract draws from the result of a call to emmeans::emmeans() (formerly lsmeans) or emmeans::ref_grid() applied to a Bayesian model.

Usage

gather_emmeans_draws(object, value = ".value", ...)

# S3 method for default gather_emmeans_draws(object, value = ".value", ...)

# S3 method for emm_list gather_emmeans_draws(object, value = ".value", grid = ".grid", ...)

Value

A tidy data frame of draws. The columns of the reference grid are returned as-is, with an additional column called .value (by default) containing marginal draws. The resulting data frame is grouped by the columns from the reference grid to make use of summary functions like point_interval() straightforward.

If object is an emmeans::emm_list(), which contains estimates from different reference grids, an additional column with the default name of ".grid" is added to indicate the reference grid for each row in the output. The name of this column is controlled by the grid argument.

Arguments

object

An emmGrid object such as returned by emmeans::ref_grid() or emmeans::emmeans().

value

The name of the output column to use to contain the values of draws. Defaults to ".value".

...

Additional arguments passed to the underlying method for the type of object given.

grid

If object is an emmeans::emm_list(), the name of the output column to use to contain the name of the reference grid that a given row corresponds to. Defaults to ".grid".

Author

Matthew Kay

Details

emmeans::emmeans() provides a convenient syntax for generating draws from "estimated marginal means" from a model, and can be applied to various Bayesian models, like rstanarm::stanreg-objects and MCMCglmm::MCMCglmm(). Given a emmeans::ref_grid() object as returned by functions like emmeans::ref_grid() or emmeans::emmeans() applied to a Bayesian model, gather_emmeans_draws returns a tidy format data frame of draws from the marginal posterior distributions generated by emmeans::emmeans().

See Also

emmeans::emmeans()