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

Create native Dirichlet multinomial family #1729

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tom-peatman
Copy link

Following discussion in #1728, I've had a go at creating a native Dirichlet multinomial family.

I've attempted to update the documentation of brmsfamily, and added some tests too.

I'm not confident that the posterior_epred.R function is correct, and probably should not have included it.

Hopefully this is helpful - please let me know if you need anything more from me. And thanks again @paul-buerkner for all your help with this!

@paul-buerkner paul-buerkner added this to the brms 2.23.0 milestone Jan 28, 2025
@paul-buerkner
Copy link
Owner

Thank you! This PR looks good overall, I think.

Why are not confident about posterior_epred? You should be able to test it by comparing its output against the known(?) mean of the dirichlet_mulinomial distribution. I currently don't have time to check this detail myself.

@tom-peatman
Copy link
Author

Thanks @paul-buerkner for taking a look at the PR - much appreciated.

I've now checked posterior_epred output for some simple models fitted to simulated data, and the output of posterior_epred is consistent with the distribution means. My understanding is that posterior_epred for the dirichlet_multinomial distribution should be the same as for the multinomial distribution (as overdispersion shouldn't influence the expected mean), so I believe that it is correct.

I also had a quick scan of the checks above in case the failed checks were related to the dirichlet_multinomial family - I don't think they are.

Copy link
Owner

@paul-buerkner paul-buerkner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now checked the PR once again in a bit more detail and found a few more minor things to adjust before the PR is ready to be merged.

# @param eta the linear predictor (of length or ncol ncat)
# @param phi the dispersion parameter
# @param log return values on the log scale?
ddirichletmultinomial <- function(x, eta, phi, log = FALSE) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this accept the same kinds of inputs as brms::dmultinomial (just with an additional phi?). E.g. is the right dimensionality for x and eta taken care of?

eta <- get_Mu(prep, i = i)
eta <- insert_refcat(eta, refcat = prep$refcat)
phi <- get_dpar(prep, "phi", i = i)
cats <- seq_len(prep$data$ncat)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the variables cats and alpha seem redundant here. Leftovers from previous versions?

eta <- insert_refcat(slice_col(eta, i), refcat = prep$refcat)
dcategorical(cats, eta = eta) * trials[i]
}
# dirichlet part included in mu
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment

@@ -587,6 +587,21 @@ posterior_epred_multinomial <- function(prep) {
out
}

posterior_epred_dirichlet_multinomial <- function(prep) {
Copy link
Owner

@paul-buerkner paul-buerkner Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is now the same as the one for multinomial (right?), perhaps it makes sense to just call it directly with a comment saying why this is valid?

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

Successfully merging this pull request may close these issues.

2 participants