R/contrasts.R
contrasts.Rd
contrasts
estimates hypothesis testing for all pairwise comparisons of the levels of a categorical in a brmsfit object.
contrasts(fit = NULL, predictor, level.sep = " - ", xlab = "Effect size",
gsub.pattern = NULL, gsub.replacement = NULL, n.posterior = 2000,
fill = "#6DCD59FF", sort.levels = NULL, html.table = FALSE,
read.file = NULL, plot = FALSE, plot.area.prop = 1, highlight = FALSE,
non.zero = FALSE)
A brmsfit object.
The name of the categorical predictor in the model fit for which contrasts will be computed. Note that the predictor must have at least 3 levels.
A character string to separate the levels in the output.
A character string with the horizontal axis label. Default is "Effect size".
A vector with character strings to be replaced
A vector with character strings to use for replacement.
Number of posterior samples to use for plotting. Default is 2000.
Color for posterior distribution fill. Default is "#6DCD59FF".
Character vector with the order to be used for levels in the predictor.
Logical to control whether estimate tables are plotted in html format. Useful for creating dynamic reports (i.e. Rmd or quarto html reports). Is FALSE (default) the table is return as a data frame object. You might have to add 'results = 'as.is' to chunk options in dynamic reports.
Character string with the name of the .rds file containing the model fit.
Logical to control if posterior distributions of estimates are plotted. Default is FALSE.
Positive number to control de proportion of the plotting area of posterior distributions that will be included. Default is 1 (the default area included by ggplot
). Useful for adding or removing empty space around distributions.
Logical to control if posterior estimates for which the 95% credible intervals do not overlap with zero are highlighted. Default is FALSE.
Logical to determine if the predictor levels are compared against zero instead. Default is FALSE.
If plot = TRUE
the function returns a ggplot object with the posterior distributions of the comparisons between predictor levels. If html = FALSE
the function will return a data frame with estimates for each comparison, otherwise it will print the estimates in a table in html format.
Estimates hypothesis testing for all pairwise comparisons of levels from a categorical predictor. The function hypothesis
is used internally. Alternatively, if argument non.zero = TRUE
the function evaluates whether each level of the predictor is different from zero.
Note that comparisons (i.e. contrasts) of categorical predictor levels when additional predictors are also included in the model are computed at the baseline (categorical predictors) or 0 (continuous predictors) value of the additional predictors. Mean-centering on additional continuous predictors can be used to ensure that the mean value of continuous predictors is used as baseline instead (Schielzeth 2010).
Araya-Salas (2022), brmsish: miscellaneous functions to customize brms bayesian regression models. R package version 1.0.0.Paul-Christian Buerkner (2017). brms: An R Package for Bayesian Multilevel Models Using Stan. Journal of Statistical Software, 80(1), 1-28. doi:10.18637/jss.v080.i01Schielzeth, H. (2010), Simple means to improve the interpretability of regression coefficients. Methods in Ecology and Evolution, 1: 103-113. https://doi.org/10.1111/j.2041-210X.2010.00012.x
{
# run model
mod <- brm(Petal.Length ~ Species, iris, chains = 1, iter = 500)
# compute constrasts with plot
contrasts(fit = mod, predictor = "Species", html.table = TRUE, plot = TRUE)
# compute constrasts without plot
contrasts(fit = mod, predictor = "Species", html.table = TRUE, plot = FALSE)
}
#> Compiling Stan program...
#> Error in .fun(model_code = .x1): Boost not found; call install.packages('BH')