Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to include an offset in a Poisson/NB model? #14

Open
robert-fitzsimmons opened this issue Oct 14, 2021 · 3 comments
Open

Comments

@robert-fitzsimmons
Copy link

My spatial unit is US counties, and I would like to include population of the county as an offset in my NB model. Is there a way to do that with your package? I did not see it mentioned in the documentation.

@seananderson
Copy link
Owner

It wouldn't be hard to add, but no, there currently isn't an offset term included. While Stan gets a bit faster for these types of models, we've been mainly working on a related package https://github.com/pbs-assess/sdmTMB that can fit similar models (and more) but with TMB instead of rstan. The two main limitations are (1) it's not Bayesian and (2) it doesn't do MVT random fields. sdmTMB can do offsets, although it currently does them via the reserved word + offset in the formula (where offset is a column named offset in your data, likely representing the log of population by county in your example) rather than offset(log(x)) as is done in R's glm().

@ericward-noaa
Copy link
Collaborator

@robert-fitzsimmons I just added this, per Sean's implementation in sdmTMB c639c3f

To implement the offset, include a column in the dataframe named 'offset', and then add '+ offset' to the formula. Let us know if there's any problems!

seananderson added a commit that referenced this issue Oct 15, 2021
@seananderson
Copy link
Owner

I think I've fixed it here 37e8c02
model.offset() expects offset(x) syntax, and we'd have to remove it from the model matrix. I just added offset as a separate argument now (as glm() allows too) and then carried it through to the predict function. I haven't extensively tested it, but that looks right to me. Of course, offset should likely be log(population) here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants