Dirichlet regressioni coefficients

Hi Andrew,

to see how this works try the following

#see vignette "brms_families", section probability models
vignette('brms_families')
#see ?rdirichlet
?brms::rdirichlet
# alpha is a concentration parameter, this is the same as nu in the vignette
# the higher the values in alpha the greater the "certainty"
# i.e. c(0.1, 0.1, 0.1) is less certain than c(100, 100, 100) but has the same relative composition: 0.33, 0.33, 0.33

# create a composition
composition <- c(a = 0.2, b = 0.5, c = 0.3) # sums to 1
certainty <- 10 # the higher the more certain, try different values
alpha <- composition * certainty # alpha for brms::rdirichlet 
alpha

# draw from distribution
set.seed(21)
rd <- rdirichlet(n = 100, alpha) # you get better estimates with higher n, try different values
colnames(rd) <- names(alpha)

# create a data frame for brms
df <- tibble(n = 1:nrow(rd))
df$y <- rd

# fit an intercept only model (just to illustrate the point)
fit <- brm(y ~ 1, df, dirichlet())
summary(fit)
fixef(fit)

# Extract the fixed effects 
# a = 0 for identifiability reasons
fix <-c(mua_Intercept = 0, fixef(fit)[, 'Estimate'])

# use back-transformation to extract the estimated composition
# see vignette
transformed <- fix |> exp()
(transformed / sum(transformed)) |> round(2)
# compare
composition

#alternatively just predict
predict(fit, newdata = 1)

In cases where you have covariates, assess the effects by looking at the logit coefficients.
To see effects in original values just predict.

I hope this helped.

Cheers

Jannik

1 Like