alashworth / test-issue-import

0 stars 0 forks source link

exp_mod_normal_lpdf unnecessarily requires positive lambda #194

Open alashworth opened 5 years ago

alashworth commented 5 years ago

Issue by jamesonquinn Monday Apr 30, 2018 at 11:30 GMT Originally opened as https://github.com/stan-dev/stan/issues/2520


Summary:

exp_mod_normal and friends should allow negative values for lambda, but do not. In fact, they should be parameterized with tau = 1/lambda, because then it would be continuous across tau=0 (with a normal distribution at tau=0).

Reproducible Steps:

Create a model in which a negative parameter is used for the exponential parameter lambda. For instance,

    if (exposcale == 0.0) {
       y_site_true ~ normal(mu_true, sigma_true);
    } else {
       y_site_true ~ exp_mod_normal(mu_true, sigma_true, sigma_true/exposcale);
    }

Call this model in a variational Bayes context (eg, call vb on it in RStan).

Current Output:

Rejecting initial value: Error evaluating the log probability at the initial value. Exception: exp_mod_normal_lpdf: Inv_scale parameter is -0.114524, but must be > 0! (in 'model17e7c6d657cfd_dp_expmod_normal' at line 33)

Expected Output:

Negative parameters make perfect sense, there's nothing wrong with them. 0 doesn't make sense in this parameterization, but switching the parameterization to tau = 1/lambda would fix that.

Current Version:

v2.17.0

alashworth commented 5 years ago

Comment by jamesonquinn Monday Apr 30, 2018 at 11:43 GMT


A workaround like:

    if (exposcale == 0.0) {
       y_site_true ~ normal(mu_true, sigma_true);
    } else if (exposcale > 0.0){
       y_site_true ~ exp_mod_normal(mu_true, sigma_true, sigma_true/exposcale);
    } else {
       target += exp_mod_normal_lpdf(-y_site_true | -mu_true, sigma_true, -sigma_true/exposcale);
    }

...works for MCMC, but still fails for variational bayes; so fixing this issue inside the stan codebase is needed to make this distribution usable in practice for cases where sign of skew is not known a priori.

alashworth commented 5 years ago

Comment by roualdes Monday Apr 30, 2018 at 15:28 GMT


Hi jamesonquinn. Thanks for your time. Two follow up thoughts.

1) For future reference, concerns related to a probability density function's definition are probably fit for stan-dev/math, which is where exp_mod_normal_lpdf is defined. For now no worries, let's see if we can help you out here.

2) It's my understanding that the exponential rate parameter lambda is necessarily, mathematically positive -- as the exponential distribution measures time until an event, the average rate of events occurring needs to be positive.

I'm certainly happy to be wrong, but I've never seen such a distribution. If my understanding is wrong, would you please point me towards a reference that details a exponentially modified Gaussian with a negative rate parameter lambda?

Otherwise, to help alleviate those warnings, have you tried putting bounds on the parameter lambda? Something like,

parameters {
// whatever else ...

real<lower=0> lambda;

/// ...
}

This and a prior that matches the support should help encourage those warnings to disappear. Further, sometimes those warnings show up at first but can safely be ignored if they stop showing up through sampling.