modelbased icon indicating copy to clipboard operation
modelbased copied to clipboard

methods other than "pairwise" for `estimate_contrasts()` fail

Open pcinereus opened this issue 2 years ago • 0 comments

In the manual for estimate_contrasts, it says: method: Contrast method. See same argument in emmeans::contrast. However, only method = "pairwise" seems to work (see MEW below). I think this is due to the following line which assumes that emmeans::contrasts will return two fields (names(level_cols) <- c("Level1", "Level2")) - yet only pairwise will return two fields.

set.seed(123)
dat <- data.frame(y =  rpois(100, 3), F =  gl(4, 20, 100))
dat_glm <- glm(y ~ F, data =  dat, family = poisson(link =  "log"))
dat_glm |> estimate_contrasts(method = "eff") 
dat_glm |> estimate_contrasts(method = "poly") 
cmat <- (cbind('1_vs_2'=c(1,-1,0,0),
              '3_vs_4'=c(0,0,1,-1),
             '1+2_vs_3+4'=c(0.5,0.5,-0.5,-0.5)))
dat_glm |> estimate_contrasts(method = list(F = cmat)) 

pcinereus avatar Jul 20 '23 23:07 pcinereus