easystats / modelbased

:chart_with_upwards_trend: Estimate effects, contrasts and means based on statistical models
https://easystats.github.io/modelbased/
GNU General Public License v3.0
234 stars 19 forks source link

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

Open pcinereus opened 1 year ago

pcinereus commented 1 year ago

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))