1

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

Eco007
  • 11
  • 2
  • To connect the GitHub issue and this post: https://github.com/strengejacke/ggeffects/issues/247 – Eco007 Mar 03 '22 at 07:52
  • One problem is that the `ordinal` package does not supply a `predict()` method to generate predictions from `clmm()` models. AFAIK, all the packages in `R` which can compute marginal effects rely on `predict()` methods, so none of them are likely to help you. This includes `margins`, `ggeffects`, and my own [`marginaleffects` package.](https://vincentarelbundock.github.io/marginaleffects/) There is a chance that `emmeans` will work, but I'm not sure. – Vincent Mar 08 '22 at 18:18
  • 1
    Hey @Vincent! FOA thank you for your great package. I stumbled about it on the ggeffects web page. I worked with margins (and mfx because margins does not support that much types of models) and it's really helpful. The results for clm models are equal to those of the mfx package (atmean = FALSE). – Eco007 Mar 10 '22 at 09:08
  • Ggpredict, emmeans and ggeffects work but they adjust for year 1981 (from 1981-2018). That's the problem. I would like to vary the predictions on the years. For now I picked 4 years (06, 08, 17, 18), collapsed them (06/08, 17/18) and applied clm models to the grouped nested dataframe/ tibble. – Eco007 Mar 10 '22 at 09:15
  • Glad you like it! Don't hesitate to ping me if you have feature requests or questions. – Vincent Mar 10 '22 at 13:34

1 Answers1

0

By definition, all levels of a random effect were drawn from the same distribution. Thus, you can not get an estimate for a particular year. Random effects are mostly used to indicate batches (e.g. subject ID). Making predictions using a new subject ID does not make sense, if the model has not seen it before. This is why there aren't coefficients for a particular subject id in the model, and thus there is no marginal effect estimate on any random effects. Random effects are just for grouping, the group names do not have intrinsic meaning.

danlooo
  • 10,067
  • 2
  • 8
  • 22
  • But where is the difference between the "other" multilevel models and the ordinal ones? I don't get the difference.... If I read your answer it should not be possible for lmer and glmer models as well? – Eco007 Mar 05 '22 at 09:02
  • Effects are estimated for the predictors. This should not affect the ordinal response. – danlooo Mar 05 '22 at 23:41