Perform model fit checks for brms models

model_fit(brmsfit, Group = NULL, Prior = FALSE)

Arguments

brmsfit

The output of a brms model. You can use VarDecomp::brms_model() to produce a brmsfit.

Group

A string containing the name of a grouping variable for the visualization of a posterior predictive check plot (e.g. "sex"). To add multiple grouping variables, use c() (e.g. c("sex", "species")).

Prior

A logical argument defining whether the brmsfit contains prior samples. If set to TRUE it will produce plots comparing the log distributions of priors and posterior samples for each covariate.

Value

Returns a list containing (a) the maximum R-hat value, (b) the minimum effective sample size, (c) traceplots, (d) posterior predictive check plots, and (e) prior and posterior sample plots (if priors are available).

Examples

if (FALSE) { # \dontrun{

md = dplyr::starwars

# Centering variables
md = md %>% 
  dplyr::select(mass, sex, height, species) %>% 
  dplyr::mutate(mass = log(mass),
         sex = dplyr::recode(sex, "male" = 1, 
                      "female" = -1, 
                      "hermaphroditic" = 0,
                      "none" = as.numeric(NA)))


# Without random effects

mod = brms_model(Chainset = 2,
                 Response = "mass", 
                 FixedEffect = c("sex","height"), 
                 Family = "gaussian", 
                 Data = md,
                 PriorSamples = TRUE)

model_fit(mod, Group = "sex", Prior = TRUE)

} # }