USEPA / spmodel

spmodel: Spatial Statistical Modeling and Prediction in R
https://usepa.github.io/spmodel/
GNU General Public License v3.0
13 stars 0 forks source link

Extending Coverage of Support Packages #20

Open mahonmb opened 2 months ago

mahonmb commented 2 months ago

The spmodel package seems like an incredible resource for fitting spatial models in R. In exploring the splm function with my own data, models fit surprisingly quickly, and the output all looks great. However, I rely heavily on the emmeans and ggeffects packages to test significance of interaction terms and post-hoc comparisons as well as figure generation.

Currently, it appears as though there is no means to extend these support packages to spmodel objects. For emmeans, I was able to figure out the recover_data function, but the emm_basis appears to be much more complicated for spmodel, likely due to the complex error structures in the spatial (and random) models.

Has there been any discussion of extending these support packages to the spmodel package?

Thanks, Mike

michaeldumelle commented 2 months ago

@mahonmb, thanks for the kind words about spmodel -- we really appreciate it!

We don't currently support extensions to emmeans (and by consequence, ggeffects), but we are always happy to hear from users about what types of functionality would be useful for their workflows. I will look into this Extending emmeans vignette and be in touch. In the meantime, perhaps you can use anova.spmodel() (see documentation here) in combination with stats::p.adjust() (see documentation here) to achieve results similar to those that you typically obtain from emmeans?

mahonmb commented 2 months ago

Hi @michaeldumelle,

Thanks for the quick response! emmeans would be the most preferred, since I could easily extend that package to make datasets for plotting purposes (bypassing the need for ggeffects).

I did use anova.spmodel() to test for overall effects of model terms, but emmeans is helpful when conducting post-hoc comparisons within groups, holding covariates at their marginal values - this is especially important when interactions are present in the model.

I will keep an eye out for your response, but I understand you are likely busy with other projects. I thought this extension could be a long-term goal that may also lead to further adoption of the package.

Best, Mike

mahonmb commented 3 weeks ago

After our conversation yesterday, I really wanted to make emmeans work for spmod. Taking from the existing emm_basis.merMOD and emm_basis.lm variants of emm_basis, I was able to get an asymptotic DF method within emmeans to work with some simple splm models - few independent variables, simple random effect, and spatial structure to the model.

This will work for my purposes, but I will see if I can incorporate the "kenward-roger" and "satterhwaite" residual DF estimation from .merMOD into the splm support.

Happy to share preliminary code, if it would be useful at this point.

michaeldumelle commented 3 weeks ago

Thanks so much @mahonmb ; we can set up a meeting via email to discuss your work on this (and I can update this issue accordingly)! As for the KR/Satterthwaite DF, my assumption is that emmeans won't work because we haven't given them derivatives. I do have Satterthwaite DF planned as part of a future spmodel update, and I will have to figure out whether it makes more sense to leverage emmeans or to create our own spmodel function. Stay tuned (though progress won't be immediate)!