Giter Site home page Giter Site logo

Comments (3)

stevejburr avatar stevejburr commented on June 23, 2024 1

Just found this bug myself - I was going to post an issue but found this one.

Rethinking will fit an NBD model correctly using rgampois - I can get results to match brms() glm.nb() and match the model parameters for some simulated data. (I can share detail on this if helpful)

However, if you run sim() on the fitted rethinking model, then the simulated data won't be right as there's a mismatch between the different parameterisations. To get the correct simulations, you need to take the fitted values and pass them to the built in rnbinom function with different transformations.

I agree with rgampois_proposed() as above for getting the right numbers out.

from rethinking.

rmcelreath avatar rmcelreath commented on June 23, 2024

Thanks. If I understand right, the issue is just that the internal Stan function has a different parameterization than is assumed to be consistent with random number generator function? The map2stan model seems to be working fine.

from rethinking.

grepinsight avatar grepinsight commented on June 23, 2024

You are right.

Based on my observation, I think the parameterization of negative binomial in stan and rethinking are different as follows:

Using X ~ Gamma(a, b) where E[X]= a * b, Var[X]=a* b^2 as a reference gamma distribution(where a is a shape parameter and b a scale parameter),

  1. In rgampois of rethinking, the focus is mu and b( which is the scale parameter of the above gamma distribution), hence its function definition.
  2. In neg_binomial_2 of stan, the focus is on mu and a(which is a shape parameter of the above gamma distribution), which is also an inverse dispersion parameter. The critical insight I learned while debugging this is that the notion of dispersion is embeded in a as opposed to b.

I was a bit confused initially, because when I think of negative binomial(or gamma-poisson mixture), I always think of poisson + overdispersion. So I automatically assumed that "scale" represented the parameter for the overdispersion, when in fact it's not.

from rethinking.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.