-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
zi mixture probs (draft) #1555
base: master
Are you sure you want to change the base?
zi mixture probs (draft) #1555
Conversation
Just a note, there's some kind of numerical instability when calculating the zero inflation mixture components, but it's only cropped up for numerically extreme inputs. For example: remotes::install_github("jsocolar/brms", ref = "zi-mixture-probs")
library(brms)
set.seed(2)
dat <- data.frame(
y = c(0, 0:10),
x = rnorm(12)
)
mix <- mixture(poisson, zero_inflated_negbinomial)
fit1 <- brm(y ~ x, dat, family = mix,
backend = "cmdstanr",
cores = 4)
fit1 yields a lot of divergences and a numerically absurd fit:
Then, |
Thank you for your effort! The structure of the log_lik_mixture function looks a bit convoluted now. I don't really want this function to be touched, since it is meant purely for mixture models set up via I think I would prefer a different internal approach only affecting pp_mixture, but I cannot fully explain is now because I need to think more about it. Could you provide me with the isolated code how to do pp_mixture for both zi and hu models, if you just implemented it for them in isolation? Without considering the current pp_mixture code? On that basis, I may add the feature myself to pp_mixture. I am sorry to cause you extra effort. |
Hi Paul, no worries. I agree this implementation is convoluted, and if you have a vision for how to simplify that's great! The implementation over on the feature request already handles the discrete zero-inflated cases, so I'll just add some logic to recapitulate the data for the hurdle cases and then hand over to you to figure out how to properly expose it through |
This is a draft PR to close #1551. I'm opening the PR as a draft to get feedback on the overall design and implementation before I work on polishing.
This PR adds the argument
z_mix = FALSE
topp_mixture
with the following effects:z_mix = FALSE
) should be unchanged.z_mix = TRUE
:zero_one_inflated_beta
) the middle component is the one-inflated state.TODO (I'll take care of these, but could use feedback from @paul-buerkner where tagged):
P(K = 2 & z = 1 | Y)
, wherez = 1
means a structural zero,z = 2
means no inflation, andz = 3
means a structural 1.A final design note: if preferred, it is possible to construct an implementation that is easier (for me) to grasp, but that supports only garden-variety zi/hu families and not mixture families that include zi/hu families as components of the mixture. It would be possible to insert this simpler implementation inside of
pp_mixture()
via the samez_mix
argument. A functioning example of how this branch of the control flow inside ofpp_mixture
might look internally is available at #1551.Here's a snippet to play with: