I have some problems with calculating the AME (…average marginal effects…) from an ordinal model (ordinal::clmm()) with random effects (in my case a four level year factor). The functions margins::margins() and mfx::probitmfx() don't work.
The ggeffects::ggpredict() function works but it has problems to specify the point(s) of random effects where I wan't to see my average marginal effects. In my case it adjusted for year = 2006 (from a range 2006,2008,2017,2018) what is not very informative for me.
Here is an example with the iris dataset. I mutated the variables no matter about it's usage. It's just an example……
#datasets::iris %>% glimpse
#get ordered variable and a factor for random effects
iris %>% mutate(species_o = ordered(Species), petal_length_cut_f = cut(iris$Petal.Length,4) )->temp
#fit model
clmm(species_o~Sepal.Width+(1|petal_length_cut_f), data = temp, link = "probit")->clmm_fit
#predict
ggpredict(clmm_fit, terms = c("petal_length_cut_f [all]", "Sepal.Width [all]"), type = "re")-> gp
This throws an error:
Predicted values can't be computed for levels of random effects from 'clmm' models. Please remove following variables from 'terms': petal_length_cut_f
Moving to lme4::lmer() I can do what I wanted:
#fit model
lmer(as.numeric(species_o) ~Sepal.Width+(1|petal_length_cut_f), data = temp)->lmer_fit
#predict
ggpredict(lmer_fit, terms = c("petal_length_cut_f [all]", "Sepal.Width [all]"), type = "re")-> gp
gp
# Predicted values of species_o
# Sepal.Width = 2
petal_length_cut_f | Predicted | 95% CI
----------------------------------------------
(0,994,2,48] | 1.01 | [-0.03, 2.04]
(2,48,3,95] | 2.00 | [ 0.97, 3.04]
(3,95,5,43] | 2.36 | [ 1.33, 3.40]
(5,43,6,91] | 3.00 | [ 1.96, 4.03]
# Sepal.Width = 2,2
petal_length_cut_f | Predicted | 95% CI
----------------------------------------------
(0,994,2,48] | 1.01 | [-0.02, 2.04]
(2,48,3,95] | 2.00 | [ 0.97, 3.03]
(3,95,5,43] | 2.36 | [ 1.33, 3.39]
(5,43,6,91] | 3.00 | [ 1.97, 4.03]
# Sepal.Width = 2,3
petal_length_cut_f | Predicted | 95% CI
----------------------------------------------
(0,994,2,48] | 1.01 | [-0.02, 2.03]
(2,48,3,95] | 2.00 | [ 0.97, 3.03]
(3,95,5,43] | 2.36 | [ 1.33, 3.39]
(5,43,6,91] | 3.00 | [ 1.97, 4.03]
… … …
asoasf
I already posted an issue in the package's GitHub but would be glad to hear about any alternatives (other regression function/ method with ggpredict or other function that can compute AMEs at specific levels of the random effects in an ordinal model).
Thanks a lot, Luise