Skip to content

neg_binomial_2_lpmf returns positive values when phi is very large (~1e15) #428

Description

@KariOlson

Summary:

I've noticed neg_binomial_2_lpmf sometimes returns values > 0. These would correspond to pmf > 1 (which is not possible). It seems to occur only when phi is a very large number (on the order of 1e15).

Description:

When neg_binomial_2_lpmf returns positive values, constraints are violated, samples are rejected. Sometimes very large phi occur due to random initialization or during sampling.

Reproducible Steps:

R script and Stan model for a reproducible example are attached.
negBin2_error.stan.txt
negBin2_error.r.txt

4 inits are given showing that large phi generates errors. This model is cut down from a more complex model so some choices may seem odd (like checking lpmf > 0 or calculating log prob of data in the transformed parameters section).

Current Output:

Reject statement is activated in chains initialized with large phi showing lmpf value calculated (and inputs).

Expected Output:

Never execute this reject with Y, mu, and phi all well-defined.

Additional Information:

R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] MASS_7.3-45 shinystan_2.2.1 shiny_0.13.2 plyr_1.8.3 rstan_2.12.1 StanHeaders_2.12.0 ggplot2_2.1.0

Current Version:

v2.12.0

Activity

  1. ghost added on Nov 1, 2016
  2. ghost
    self-assigned this
    on Nov 1, 2016
  3. KariOlson commented on Nov 2, 2016

    @KariOlson
    Author

    right, a poisson would be a better model in that case... I've tried it many revisions of this model ago and found that the poisson had some significant issues in the larger context (and usually phi is not this large). I'm not initializing with large phi intentionally in my model, just using it to create reproducibility of the error.

  4. added this to the milestone on Nov 15, 2016
  5. modified the milestones: , on Dec 26, 2016
  6. ghost closed this as completedon Dec 26, 2016
  7. modified the milestones: , on Apr 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions