Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dirichlet and Multinomial Models #463

Closed
paul-buerkner opened this issue Jun 25, 2018 · 11 comments
Closed

Dirichlet and Multinomial Models #463

paul-buerkner opened this issue Jun 25, 2018 · 11 comments
Labels
Milestone

Comments

@paul-buerkner
Copy link
Owner

The Dirichlet distribution is a multivariate generalization of the beta distribution and may not only be used as prior for some parameters but also as response distribution if the response is a probability vector of more than two categories. I am not yet sure about an appropriate interface for this model, because it requires multiple columns as response input, but maybe I get an idea at some point. The implementation can otherwise closely follow that of the categorical distribution.

@jamesrrae
Copy link

jamesrrae commented Jun 26, 2018

Great. This would address the issue I raised in this feature request, no?:

#396

I guess the situation I'm interested in is what to do when one has multiple outcome variables that are all probability vectors.

@paul-buerkner
Copy link
Owner Author

Not exactly. The Dirichlet distribution is not a multivariate distribution of correlated (in the sense of a correlation matrix) beta variables. Rather the dirichlet distribution is to beta what categorical is to bernoulli and neither of them is multivariate in the sense of #396.

@jamesrrae
Copy link

That's too bad. I was hopeful that it may have resolved the issue that comes up in data I come across pretty frequently (i.e., multiple beta variables)!

@paul-buerkner
Copy link
Owner Author

I think a reasonable way to specify the response of a Dirichlet model would be to use a matrix column in the data. For instance

A <- rbind(
  c(0.2, 0.3, 0.5),
  c(0.8, 0.1, 0.1)
)
df <- data.frame(x = rnorm(2)
df$A <- A
brm(A ~ x, data = df, family = Dirichlet())

@paul-buerkner
Copy link
Owner Author

The same structure could be used to implement multinomial models. Updating the title accordingly.

@paul-buerkner paul-buerkner changed the title Dirichlet Models Dirichlet and Multinomial Models Aug 14, 2018
@paul-buerkner
Copy link
Owner Author

I thinks this may not be the right place to ask since this is about multinomial responses. I would you suggest, you first look at the doc of ?set_prior first. If you still have questions, ask at https://discourse.mc-stan.org/

@paul-buerkner
Copy link
Owner Author

Multinomial and Dirichlet models can now be estimated in the GitHub version of brms.

@szuniga07
Copy link

szuniga07 commented Jan 30, 2019 via email

@Robinlovelace
Copy link

Just a follow-up on this, I have an application for Dirichlet regression: estimating the % of trips in cities, zones and desire lines made by different modes of transport such as car, bike, walk.

Just discovered that you can do it in a Bayesian framework with brms, great work @paul-buerkner! FYI the minimal example I put together based on the code above was as follows:

# install.packages("brms")
library(tidyverse)
library(brms)
A = rbind(
  c(0.2, 0.3, 0.5),
  c(0.8, 0.1, 0.1)
)
df = data.frame(x = rnorm(2))
df$A = A
m = brm(A ~ x, data = df, family = dirichlet())

res  = predict(m, data.frame(x = 0:3))
res_matrix = res[, 1, ]
rowSums(res_matrix)
res_df = as.data.frame(res_matrix) %>% 
  mutate(x = 0:3) %>% 
  pivot_longer(matches("[0-3]"))
ggplot(res_df) +
  geom_area(aes(x, value, fill = name))

Which generated this:

image

Out of interest, would you say that this is a good approach to tackle the issue of predicting mode splits with confidence intervals? See here for some city data I've been looking at, would be great to get a solid predictive model of cycling so that you could predict the % increase with changes to multiple parts of transport systems:

https://github.com/ATFutures/who3/tree/master/scenarios

@szuniga07
Copy link

szuniga07 commented Nov 10, 2019 via email

@paul-buerkner
Copy link
Owner Author

Please ask brms related questions on https://discourse.mc-stan.org/ using the Interfaces - brms tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants