paul-buerkner/brms

"Marginal" hurdle models

Open

#641 opened on Apr 14, 2019

View on GitHub
 (6 comments) (1 reaction) (0 assignees)R (1,402 stars) (220 forks)batch import
familyfeaturegood first issue

Description

I think adding "marginal" versions of the current hurdle models supported in brms would be extremely useful. Where "marginal" means that we model the effect of covariates on the overall outcome E(Y | b) instead of the conditionally positive part E(Y | Y > 0, b). This can be done simply by solving for the conditional mean as a function of the overall mean (cf., Smith et al https://doi.org/10.1177/0962280215592908). Here's a hackish example where the hurdle_gamma lpdf is changed to represent the marginal version using the custom_family function.

# Custom marginal gamma two-part ------------------------------------------
hurdle_gamma_mtp <- custom_family(
    "hurdle_gamma_mtp",
    dpars = c("shape","mu", "hu"),
    lb = c(0, NA, 0),
    ub = c(NA, NA, 1),
    links = c("log", "identity", "logit"),
    type = "real"
)

scode <- "
/* Marginal hurdle gamma log-PDF of a single response
* logit parameterization of the hurdle part
* Args:
*   y: the response value
*   alpha: shape parameter of the gamma distribution
*   mu: overall mu
*   hu: linear predictor for the hurdle part
* Returns:
*   a scalar to be added to the log posterior
*/
real hurdle_gamma_mtp_lpdf(real y, real alpha, real mu, real hu) {
    if (y == 0) {
        return bernoulli_logit_lpmf(1 | hu);
    } else {
        real beta;
        beta = alpha * exp(-(mu - log1m_inv_logit(hu)));
        return bernoulli_logit_lpmf(0 | hu) +
        gamma_lpdf(y | alpha, beta);
}
}
"
hurdle_gamma_mtp_stanvars <- stanvar(scode = scode,
                                     block = "functions")

As you can see the only real difference is solving for the conditionally positive mean using exp(-(mu - log1m_inv_logit(hu)));

Although the models are highly similar, I'm not sure if this is an easy change with regards to brms internal code.

Contributor guide