-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
incorrect mixture probabilities returned when mixtures include hurdle families #1552
Comments
I see the problem. However, I would not want to prevent these models from being excluded from mixture models because of this. Perhaps a warning could be sufficient. |
I defer to you (obviously), but want to make sure that it's clear that this isn't a problem in set.seed(2)
dat <- data.frame(
y = c(rep(0, 100), runif(10) rnorm(5, .5, .1))
)
mix <- mixture(gaussian, zero_inflated_beta)
make_stancode(y ~ 1, dat, family = mix) Yields stan code including for (n in 1:N) {
array[2] real ps;
ps[1] = log(theta1) + normal_lpdf(Y[n] | mu1[n], sigma1);
ps[2] = log(theta2) + zero_inflated_beta_lpdf(Y[n] | mu2[n], phi2, zi2);
target += log_sum_exp(ps);
} But it's not correct to for (n in 1:N) {
array[2] real ps;
if(y[n] == 0){
target += log(theta2) + log(zi2);
} else {
ps[1] = log(theta1) + normal_lpdf(Y[n] | mu1[n], sigma1);
ps[2] = log(theta2) + log1m(zi2) + beta_lpdf(Y[n] | mu2[n], phi2);
target += log_sum_exp(ps);
}
} Here's a simple example that shows the consequences for parameter recovery: library(brms)
set.seed(2)
dat <- data.frame(
y = c(rep(0, 100), runif(20), rnorm(20, .5, .1))
)
mix <- mixture(gaussian, zero_inflated_beta)
prior <- c(
prior(normal(.5, .05), Intercept, dpar = mu1),
prior(normal(0, .2), Intercept, dpar = mu2),
prior(lognormal(1,1), sigma1, lb = 0.01)
)
fit <- brm(y ~ 1, dat, family = mix,
prior = prior,
backend = "cmdstanr",
cores = 4)
summary(fit) I included the prior
Even with the I think that |
Note that the Stan code for mixtures including |
Ah, that makes sense. So the problem are the continuoues zi/hu families, such as zero_inflated_lognormal? |
Yup! |
Got it. Will change accordingly. |
Fixed :-) |
While tinkering with #1551, I realized that
mixture()
misbehaves as follows:If I do
I error with
This makes sense.
But if I do:
brms
doesn't complain. Moreover, if I doI get (in addition to a bunch of divergences) the final output
This is incorrect; rows 1 and 2 are structurally guaranteed to arise from the zero-one-inflated-beta component which puts probability mass rather than probability density over zero and one.
I think the solution is to prohibit hurdle families as arguments to
mixture()
.The text was updated successfully, but these errors were encountered: