Open robert-fitzsimmons opened 2 years ago
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()
.
@robert-fitzsimmons I just added this, per Sean's implementation in sdmTMB https://github.com/seananderson/glmmfields/commit/c639c3f15abce53ff084c5b0d038c6b33be33ec5
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!
I think I've fixed it here https://github.com/seananderson/glmmfields/commit/37e8c02368f08cecfa01ead7bd8b8a8b35ebbbd8
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.
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.