Plot R2 values of brms models

plot_R2(PosteriorSamples, Colors = NULL)

Arguments

PosteriorSamples

The estimates of a brms model after variance decomposition. You can use VarDecomp::brms_model() to produce a brmsfit and then VarDecomp::var_decomp() to produce the posterior samples.

Colors

A vector with string of the colors to be attributed to each variable ordered by R2, with residual at the end (e.g. c("blue", "green", "gray")).

Value

Returns a bar plot with the proportion of variance explained by each variable.

Examples

if (FALSE) { # \dontrun{
md = dplyr::starwars

# Centering variables
md = md %>% 
  dplyr::select(mass, sex, species) %>% 
  dplyr::mutate(mass = log(mass),
         sex = dplyr::recode(sex, "male" = 1, 
                      "female" = -1, 
                      "hermaphroditic" = 0,
                      "none" = as.numeric(NA)))
  
  
mod = brms_model(Chainset = 2,
                 Response = "mass", 
                 FixedEffect = "sex", 
                 RandomEffect = "species",
                 Family = "gaussian", 
                 Data = md)

PosteriorSamples = var_decomp(mod)
plot_R2(PosteriorSamples)

} # }