rvlenth / emmeans

Estimated marginal means
https://rvlenth.github.io/emmeans/
364 stars 32 forks source link

Error in UseMethod("cld") : no applicable method for 'cld' applied to an object of class "emmGrid" #418

Closed Easonchen12 closed 1 year ago

Easonchen12 commented 1 year ago

I used the 1.8.5 version of the "emmeans" package. My R version is 4.2.2

My mixed-liner model

m1<-lmer(Respone~A*B+(1|C), data = DATA) # The A is Categorical variable, The B is continuous variable. m1.emmeans<-emmeans(m1,"A",data=DATA,var="B") m1.emmeans pairs(m1.emmeans) cld(m1.emmeans,Letters=letters)

when i run,it showed

Error in UseMethod("cld") : no applicable method for 'cld' applied to an object of class "emmGrid"

Can you help me with that?

rvlenth commented 1 year ago

The generic for cld is in the multcomp package. I think it will work if you do multcomp::cld(m1.emmeans,Letters=letters).

If not, then I think there is some issue with method registration. Is emmeans actually loaded? It will probably get straightened-out by unloading and reloading one of the packages, or by restarting R.

SchmidtPaul commented 1 year ago

I can add that in my experience[^1], this resolves the issue in most cases:

  1. Install {emmeans}, {multcomp} and {multcompView}
  2. Restart R session
  3. Load {emmeans}, {multcomp} and {multcompView}
  4. Run code again

[^1]: My experience being people in R workshops who had never used cld() before and are seeing the error when trying it for the first time. There is always at least one person per workshop with this error; these steps usually resolve it.

rvlenth commented 1 year ago

@SchmidtPaul Thanks. I know I have seen this kind of error reported before, but hadn't tracked where or how to fix it. Having the generic for an S3 method outside of one of the basic packages, and not in the package where a method resides, is one of those pathological situations...

rvlenth commented 1 year ago

I think this is resolved, so am closing this issue.