rvlenth / emmeans

Estimated marginal means
https://rvlenth.github.io/emmeans/
341 stars 30 forks source link

Adding (new) interaction using emmeans #415

Closed Dallak closed 1 year ago

Dallak commented 1 year ago

I constructed a bayesian model with three fixed factors but I didn’t include the interaction between the second and third factors (B+C). Something like this:

var ~ A*B+C

I want to use this package to run pairwise comparison. However, I’m wondering if there a way to include the interaction between B*C after the model is run. I mean based on the model output using functions like emmeans(m1, …). If not, do you have any recommendation other than running the model from the beginning which takes hours.

Thanks

rvlenth commented 1 year ago

emmeans() summarizes an existing model. We have no way of knowing what the interaction effects would be if they have not already been estimated. The only way the feature you describe could be implemented would be for emmeans() to prepare a call to re-fit the model, using the same model-fitting function and a different formula. If it would take hours to re-fit the model manually, it would take hours for emmeans() to do it. My only suggestion is to re-fit the model.

There is a submodel feature in emmeans() for removing interactions; it works by constraining the linear functions being estimated. Even then, it doesn't even necessarily arrive at the same solution as would be obtained by re-fitting the model.

Dallak commented 1 year ago

Thanks for your time and input. I see.