rvlenth / emmeans

Estimated marginal means
https://rvlenth.github.io/emmeans/
358 stars 31 forks source link

Contrasts on ggpredict Output #294

Closed awaldman123 closed 3 years ago

awaldman123 commented 3 years ago

I have been calculating marginal means taking into account all sources of variation (fixed effects, zero-inflation, and random effects) using the ggpredict command (from the ggeffects package) and type="sim" argument.

However, I tried using the output of ggpredict as part of a call to the emmeans contrasts function and got the following error:

Error in UseMethod("contrast") : no applicable method for 'contrast' applied to an object of class "c('ggeffects', 'data.frame')"

Is there a way to coerce the data frame to be read by the contrasts function?

Thanks for your help!

rvlenth commented 3 years ago

No. contrast requires an emmGrid object.

awaldman123 commented 3 years ago

Thanks! I assume I can't use the original model object and ggeffects data frame to create an emmGrid object somehow?

rvlenth commented 3 years ago

No, it's not even possible, because essential info is not present, like the covariances between the EMMs.

awaldman123 commented 3 years ago

Thanks! My apologies for the naive question but would it be viable to take the ggeffects output (ie predicted marginal means and confidence intervals) and perform pairwise contrasts outside of the emmeans package (ie within R or some other statistical software) using T-tests and a p-value adjustment of my choosing? I'm just curious as to whether that would mirror what the contrast function is doing and provide the same result as if the contrasts were performed within the emmeans package? Since I am using mixed models, I assume I would use paired T-tests for my pairwise comparisons?

rvlenth commented 3 years ago

I guess my answer is that these things can already be done inside of the emmeans package, which is my package, and if you want it done by some other package, I have no role nor interest in facilitating that - and you should ask that other package's developer instead. Plus I have already explained that you don't have all the needed info. What's wrong with using emmeans to begin with?

awaldman123 commented 3 years ago

My apologies, I would like to be able to perform contrasts on estimated marginal means that take into account the zero inflation component of my glmmtmb models which I think only ggpredict does. Therefore, I wanted to garner a better understanding of what the contrast function does under the hood (R is a bit new to me) to know if I could get around the formatting issue you had described.

rvlenth commented 3 years ago

I'm closing this as I think I have answered the question as well as I can.