paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.27k stars 182 forks source link

AR in negbinomial model #77

Closed alireza202 closed 7 years ago

alireza202 commented 8 years ago

In my mode:

brm(formula = y ~ x + (x | item), 
    data = df,
    family = "negbinomial") -> fit_model

I'd like to have the intercept as an autoregressive. I know this feature is not implemented for negbinomial, but any pointers on how to achieve it? Or any plans to implement it in the near future?

paul-buerkner commented 8 years ago

Implementing ARMA structures in non-gaussian models is a bit complicated since we don't naturally have some sort of "residuals". It is possible to add those using a random effect with as many levels as observations in the data and then build the ARMA structure around it. I haven't found the time to do it though.

Specifically for negbinomial models, I am skeptical that this will work though, because we already have an overdispersion parameter dealing with excess variance. This parameter will conflict with the "residual" random effects and convergence will be problematic. As soon as ARMA models are implemented for non-gaussian models, I would probably recommand using the poisson family instead of negbinomial.

Another possibility is using the new cor_bsts correlation structure to fit simple bayesian time series models. Here is an example with one of the build in datasets (which is not perfectly suited for this kind of model):

fit <- brm(count ~ log_Age_c + log_Base4_c * Trt_c,
            data = epilepsy, family = negbinomial(),
            autocor = cor_bsts(~visit|patient))

The current drawback of cor_bsts is that I haven't yet implemented forecasting in the way described in the blog post you send me. Everything else appears to work fine though.

alireza202 commented 8 years ago

Great! I'll try out cor_bsts and let you know. Although it is a bit difficult to assess it without prediction...

paul-buerkner commented 8 years ago

You can predict (even with newdata) but you can't do the forecasting stuff explained in the blog post. Am 14.06.2016 20:03 schrieb "Ali Roshan Ghias" notifications@github.com:

Great! I'll try out cor_bsts and let you know. Although it is a bit difficult to assess it without prediction...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/paul-buerkner/brms/issues/77#issuecomment-225965299, or mute the thread https://github.com/notifications/unsubscribe/AMVtAKFKmcnGwPXhiBiXQBRV_ImvXs7-ks5qLu0KgaJpZM4I018H .

paul-buerkner commented 8 years ago

Ok, this was only partially correct. You can predict with newdata but the local level terms won't be included in the prediction in this case. This is not an implementation problem but more a conceptual one, because the local level terms are not fully compatible with the flexibility that brms offers when predicting based on new data. As soon as I have a clear concept of what is reasonable to allow, I will incorporate the local level terms in the prediction of new data.

paul-buerkner commented 7 years ago

I am closing this issue, as I currently don't see a reasonable way to implement AR structures in negbinomial models.

jacob-long commented 6 years ago

@paul-buerkner, do you also see the implementation of AR residual structures for all/most GLMs as impractical, or is this latest comment referring just to the special considerations for negative binomial models?

paul-buerkner commented 6 years ago

I am not entirely sure. If you have a reference implemantation (stan code or similar) for AR in certain GLMs, I am happy to take a look and see if implementing it in brms is feasible.

Am 27.10.2017 16:57 schrieb "Jacob Long" notifications@github.com:

@paul-buerkner https://github.com/paul-buerkner, do you also see the implementation of AR residual structures for all/most GLMs as impractical, or is this latest comment referring just to the special considerations for negative binomial models?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/paul-buerkner/brms/issues/77#issuecomment-340012110, or mute the thread https://github.com/notifications/unsubscribe-auth/AMVtAG_SWgb1dcInC-zJbJJV7C1zzJazks5swf1sgaJpZM4I018H .

statwonk commented 6 years ago

I've been poking around in this area. Let me share some candidate models (PAR(p), PEWMA) I've found. :-)

I'm a bit intimidated to write them directly into stan, but I plan to at least give it a shot. Hoping to work on the random number generator over the next week.

statwonk commented 6 years ago

Ah ha, http://www.utdallas.edu/~pxb054000/code/pests.r has the rng, pewmadgp. 👍

paul-buerkner commented 6 years ago

Great! If you get them running in Stan, I am happy to take a look if they make sense for brms.

oguzhanogreden commented 5 years ago

@statwonk did you get to work on this? And @paul-buerkner has there been any development that changed your position?

statwonk commented 5 years ago

@oguzhanogreden I haven't yet, but I am interested in the model. I could work on some simulations to identify properties / challenges. I need to refresh on the theoretical properties of the models.

oguzhanogreden commented 5 years ago

I'm interested in this as well.

Would you like to make a repository with an issue that collects your ideas on how to approach this? We can then refine the plan and I can commit to parts of it.