-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
Add zero-inflated Beta-binomial distribution #1311
Changes from 7 commits
86b08c9
cf8fab7
5ac1c9f
53a5187
c7e576a
e71061e
fc0ae65
6abc29a
3189917
6d672f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,6 +389,7 @@ export(dstudent_t) | |
export(dvon_mises) | ||
export(dwiener) | ||
export(dzero_inflated_beta) | ||
export(dzero_inflated_beta_binomial) | ||
export(dzero_inflated_binomial) | ||
export(dzero_inflated_negbinomial) | ||
export(dzero_inflated_poisson) | ||
|
@@ -516,6 +517,7 @@ export(pskew_normal) | |
export(pstudent_t) | ||
export(pvon_mises) | ||
export(pzero_inflated_beta) | ||
export(pzero_inflated_beta_binomial) | ||
export(pzero_inflated_binomial) | ||
export(pzero_inflated_negbinomial) | ||
export(pzero_inflated_poisson) | ||
|
@@ -587,6 +589,7 @@ export(waic) | |
export(weibull) | ||
export(wiener) | ||
export(zero_inflated_beta) | ||
export(zero_inflated_beta_binomial) | ||
export(zero_inflated_binomial) | ||
export(zero_inflated_negbinomial) | ||
export(zero_inflated_poisson) | ||
|
@@ -607,6 +610,8 @@ importFrom(bridgesampling,bayes_factor) | |
importFrom(bridgesampling,bridge_sampler) | ||
importFrom(bridgesampling,post_prob) | ||
importFrom(coda,as.mcmc) | ||
importFrom(extraDistr,dbbinom) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you seem to access these function via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What’s the best approach? If we call via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having it in Suggests is the most sensible thing to do I think. Perhaps for the functions that require a package unders Suggests could be starting with a |
||
importFrom(extraDistr,pbbinom) | ||
importFrom(grDevices,devAskNewPage) | ||
importFrom(graphics,plot) | ||
importFrom(loo,.compute_point_estimate) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* zero-inflated beta-binomial log-PDF of a single response | ||
* Args: | ||
* y: the response value | ||
* trials: number of trials of the binomial part | ||
* mu: mean parameter of the beta distribution | ||
* phi: precision parameter of the beta distribution | ||
* zi: zero-inflation probability | ||
* Returns: | ||
* a scalar to be added to the log posterior | ||
*/ | ||
real zero_inflated_beta_binomial_lpmf(int y, int trials, | ||
real mu, real phi, real zi) { | ||
if (y == 0) { | ||
return log_sum_exp(bernoulli_lpmf(1 | zi), | ||
bernoulli_lpmf(0 | zi) + | ||
beta_binomial_lpmf(0 | trials, | ||
mu * phi, | ||
(1 - mu) * phi)); | ||
} else { | ||
return bernoulli_lpmf(0 | zi) + | ||
beta_binomial_lpmf(y | trials, mu * phi, (1 - mu) * phi); | ||
} | ||
} | ||
/* zero-inflated beta-binomial log-PDF of a single response | ||
* logit parameterization of the zero-inflation part | ||
* Args: | ||
* y: the response value | ||
* trials: number of trials of the binomial part | ||
* mu: mean parameter of the beta distribution | ||
* phi: precision parameter of the beta distribution | ||
* zi: linear predictor for zero-inflation part | ||
* Returns: | ||
* a scalar to be added to the log posterior | ||
*/ | ||
real zero_inflated_beta_binomial_logit_lpmf(int y, int trials, | ||
real mu, real phi, real zi) { | ||
if (y == 0) { | ||
return log_sum_exp(bernoulli_logit_lpmf(1 | zi), | ||
bernoulli_logit_lpmf(0 | zi) + | ||
beta_binomial_lpmf(0 | trials, | ||
mu * phi, | ||
(1 - mu) * phi)); | ||
} else { | ||
return bernoulli_logit_lpmf(0 | zi) + | ||
beta_binomial_lpmf(y | trials, mu * phi, (1 - mu) * phi); | ||
} | ||
} | ||
/* zero-inflated beta-binomial log-PDF of a single response | ||
* logit parameterization of the binomial part | ||
* Args: | ||
* y: the response value | ||
* trials: number of trials of the binomial part | ||
* eta: linear predictor for the beta part | ||
* phi: precision parameter of the beta distribution | ||
* zi: zero-inflation probability | ||
* Returns: | ||
* a scalar to be added to the log posterior | ||
*/ | ||
real zero_inflated_beta_binomial_blogit_lpmf(int y, int trials, | ||
real eta, real phi, real zi) { | ||
if (y == 0) { | ||
return log_sum_exp(bernoulli_lpmf(1 | zi), | ||
bernoulli_lpmf(0 | zi) + | ||
beta_binomial_lpmf(0 | trials, | ||
eta * phi, | ||
(1 - eta) * phi)); | ||
} else { | ||
return bernoulli_lpmf(0 | zi) + | ||
beta_binomial_lpmf(y | trials, eta * phi, (1 - eta) * phi); | ||
} | ||
} | ||
/* zero-inflated beta-binomial log-PDF of a single response | ||
* logit parameterization of the binomial part | ||
* logit parameterization of the zero-inflation part | ||
* Args: | ||
* y: the response value | ||
* trials: number of trials of the binomial part | ||
* eta: linear predictor for the beta part | ||
* phi: precision parameter of the beta distribution | ||
* zi: linear predictor for zero-inflation part | ||
* Returns: | ||
* a scalar to be added to the log posterior | ||
*/ | ||
real zero_inflated_beta_binomial_blogit_logit_lpmf(int y, int trials, | ||
real eta, real phi, | ||
real zi) { | ||
if (y == 0) { | ||
return log_sum_exp(bernoulli_logit_lpmf(1 | zi), | ||
bernoulli_logit_lpmf(0 | zi) + | ||
beta_binomial_lpmf(0 | trials, | ||
eta * phi, | ||
(1 - eta) * phi)); | ||
} else { | ||
return bernoulli_logit_lpmf(0 | zi) + | ||
beta_binomial_lpmf(y | trials, eta * phi, (1 - eta) * phi); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why and where do we need processx in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this should be in something separate, if needed at all? It was just throwing a warning in
devtools::check
as it get’s called on R/backends.R#L633 but wasn’t in the list of suggested packagesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. This had been added recently. I will add it separately to master.