- data
Long-format data.frame
of draws such as returned by
spread_draws()
or gather_draws()
. If data
is a grouped data frame, comparisons will be made within groups (if
one of the groups in the data frame is the by
column, that specific
group will be ignored, as it is not possible to make comparisons both
within some variable and across it simultaneously).
- variable
Bare (unquoted) name of a column in data representing the
variable to compare across levels. Can be a numeric variable (as in
long-data-frame-of-draws format) or a posterior::rvar
.
- by
Bare (unquoted) name of a column in data that is a
factor
or ordered
. The value of variable
will be
compared across pairs of levels of this factor
.
- fun
Binary function to use for comparison. For each pair of levels of
by
we are comparing (as determined by comparison
), compute the
result of this function.
- comparison
One of (a) the comparison types ordered
,
control
, pairwise
, or default
(may also be given as
strings, e.g. "ordered"
), see Details; (b) a user-specified
function that takes a factor
and returns a list of pairs of names of
levels to compare (as strings) and/or unevaluated expressions containing
representing the comparisons to make; or (c) a list of pairs of names of
levels to compare (as strings) and/or unevaluated expressions representing
the comparisons to make, e.g.: list(c("a", "b"), c("b", "c"))
or
exprs(a - b, b - c)
, both of which would compare level "a"
against
"b"
and level "b"
against "c"
. Note that the
unevaluated expression syntax ignores the fun
argument, can include
any other functions desired (e.g. variable transformations), and can even
include more than two levels or other columns in data
. Types (b) and
(c) may use named lists, in which case the provided names are used
in the output variable
column instead converting the unevaluated
expression to a string. You can also use emmeans_comparison()
to generate
a comparison function based on contrast methods from the emmeans
package.
- draw_indices
Character vector of column names that should be treated
as indices of draws. Operations are done within combinations of these values.
The default is c(".chain", ".iteration", ".draw")
, which is the same names
used for chain, iteration, and draw indices returned by tidy_draws()
.
Names in draw_indices
that are not found in the data are ignored.
- ignore_groups
character vector of names of groups to ignore by
default in the input grouping. This is primarily provided to make it
easier to pipe output of add_epred_draws()
into this function,
as that function provides a ".row"
output column that is grouped,
but which is virtually never desired to group by when using compare_levels
.