gavinsimpson / gratia

ggplot-based graphics and useful functions for GAMs fitted using the mgcv package
https://gavinsimpson.github.io/gratia/
Other
206 stars 28 forks source link

gratia support for other regression packages #227

Open seanhardison1 opened 1 year ago

seanhardison1 commented 1 year ago

Hi! I love this package and I use it all the time. It's my go-to for visualizing and diagnosing GAMs on the fly.

My only critique is that I can't use it with other packages that I also use frequently like base stats or glmmTMB. I know it's a big ask, but it would be great to see gratia support for these packages in the future.

Thanks!

Sean

gavinsimpson commented 1 year ago

I've been a bit inconsistent with this but where appropriate I planned to support lm() and glm() from base R — appraise() works for those models for example. I hadn't considered supporting glmmTMB(); I'll be more motivated to do this if/once we have penalised splines in glmmTMB().

Are there models/functions/packages that you are especially interested in? And which functions in gratia would you like to see supported for them?

There are other more general options for a wider range of model types, like marginaleffects.

seanhardison1 commented 1 year ago

That makes sense. I was not aware that appraise works for lm and glm, but that's great to hear. The functions in gratia that I use the most are draw and appraise, so those would have to be my top choices.

Outside of mgcv, glmmTMB, and base R, the only other modeling package I use frequently is sdmTMB. sdmTMB models can include smooths fitted via mgcv, but I haven't tried them with gratia yet. It would be very cool to be able to visualize spatiotemporal predictions from sdmTMB models using draw alone, similar to how you can use draw to visualize 2D smooths etc. The predictions from sdmTMB models are already tidy too!

Tagging @seananderson in the hopes that this one day becomes reality

authagag commented 1 year ago

Opening this up again as glmmTMB has added spline support, see https://github.com/glmmTMB/glmmTMB/issues/928

There is some discussion of adding support in gratia. Looking through the code it seems that there would need to be a draw.glmmTMB method as well as a smooths.glmmTMB method to find all the smooth terms in the glmmTMB structure. Is there anything I am missing, pretty sure there is more

gavinsimpson commented 1 year ago

@authagag Oh, that saves me a job then as I had been looking at what would be required to add smooths to glmmTMB, gamm4-style.

The main thing that would be needed would be smooth_estimates() and parametric_effects() methods for class "glmmTMB". Assuming that glmmTMB does sensible things like store the actual mgcv smooth objects in model$smooths then most things should just work, and specific methods could simply just call the "gam" methods for the plotting code. Things could get more complex if the objects returned by glmmTMB() don't have many of the things that I'd find in a "gam" object as then specific methods for many internal functions could be needed.

I can take a look at glmmTMB/glmmTMB#928 and install from the repo and see what would be needed from gratia's point of view.