Skip to contents

This function takes as input a brms model fit for a factorial design and a group specification (one subset of the design cells) and returns the posterior draws for that group. If no group is specified, the returned draws are grand means.

Usage

filter_cell_draws(fit, group = NULL, colname = "draws")

Arguments

fit

An object of class brmsfit.

group

An expression specifying the group to filter the draws for.

colname

A string specifying the column name of the returned data frame; defaults to 'draws'.

Value

A draws_df object containing posterior draws for the specified group and additional metadata.

Note

The faintr package currently does not support multivariate models and models that use families categorical, dirichlet, multinomial, and logistic_normal. Furthermore, models must not include special effect terms mo(), mi(), me(), and cs() for fixed effects. Also note that faintr currently does not support models where the intercept is a population-level parameter (class b), as is the case when using the 0 + Intercept syntax in the brm function call.

References

Bürkner, P.-C. (2017). brms: An R Package for Bayesian Multilevel Models Using Stan. Journal of Statistical Software, 80(1), 1-28. doi:10.18637/jss.v080.i01

Examples

if (FALSE) {
# fit a linear mixed effects model on data from a 2 x 2 factorial design
## regress voice pitch against gender and context
fit <- brms::brm(formula = pitch ~ gender * context + (1 | subject + sentence),
                 data = politeness)

# get the draws for female speakers in informal contexts
filter_cell_draws(fit, gender == "F" & context == "inf")

# get the draws for male speakers or informal contexts
filter_cell_draws(fit, gender == "M" | context == "inf")

# averaged over gender, get the draws for all but polite contexts
filter_cell_draws(fit, context != "pol")

# get the posterior draws averaged over all factors (grand mean)
filter_cell_draws(fit)
}