-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1311 from hdrab127/master
Add zero-inflated Beta-binomial distribution
- Loading branch information
Showing
21 changed files
with
299 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.