1

I have an ordinal model created using clmm() and I am trying to predict for a logistic regression. The function predict() does not work, so I am attempting predict.clm() but get this error:

Error in predict.clm() : could not find function "predict.clm"

Any help would be appreciated. The package is updated, R and Rstudio are both updated, and the package is loaded to Rstudio. I am new to R and am not sure how I would go about fixing this or otherwise go about predicting variables for my model.

I am wondering if I should go about changing my model to use the function polr() in package MASS as predict() does not work for the function clmm() which is what my model currently uses. Thank you in advance.

ETA: example, an behavior dataset

Proximity <- c(1, 1, 2, 1, 3, 2, 1, 1, 2, 1) #ordinal variable
Treatment <- c("control", "control", "control", "familiar", "familiar", "familiar", "familiar", "unfamiliar", "unfamiliar", "unfamiliar") #categorical
Event <- c("L", "L", "L", "L", "L", "I", "I", "I", "I", "I") #categorical
Temperature <- c(70, 72, 72, 69, 79, 60, 63, 70, 74, 65) #numerical

#I also have nested random effects but have not included them for simplicity

Prox <- data.frame(Proximity, Treatment, Event, Temperature)

pro.1 <- clmm(Proximity ~ Treatment + Event + Temperature)  

predict.clm(pro.1, Prox) #this is where I get the error
jay.sf
  • 60,139
  • 8
  • 53
  • 110

1 Answers1

1

Normally calling predict should be sufficient. This should automatically call the method predict.clm.

However, ?ordinal::clmm states:

This is a [...] improved implementation of CLMMs. The old implementation is available in clmm2. Some features are not yet available in clmm [...].

I suggest this is either not implemented or it is a bug. You could try clmm2 alternatively. Example:

library(ordinal)

## clmm -- doesn't work
fmm1 <- clmm(rating ~ temp + contact + (1|judge), data = wine)
predict(fmm1)
# Error in UseMethod("predict") : 
#   no applicable method for 'predict' applied to an object of class "clmm"
ordinal:::predict.clm(fmm1)
# Error in get_clmDesign(fullmf = object, terms.list = terms.list, contrasts = contrasts) : 
#   all(sapply(terms.list, inherits, "terms")) is not TRUE

## clmm2 -- works!
fmm2 <- clmm2(rating ~ temp + contact, random=judge, data = wine)   
predict(fmm2)
# [1] 0.41952700 0.47195487 0.55026797 ...
ordinal:::predict.clm2(fmm2)
# [1] 0.41952700 0.47195487 0.55026797 ...

stopifnot(all.equal((fmm1$coefficients), fmm2$coefficients[-7], tol=10e-6))

(PS: Referring to ordinal version 2019.12-10 and R version 4.0.0)

jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • Thank you for your response - I don't think I can use clmm2() because I don't see where it can accommodate for nested random effects. – Hannah Miriam Dancy May 03 '20 at 05:29
  • @HannahMiriamDancy I see. I just saw that this has already been issued: https://github.com/runehaubo/ordinal/issues/20 – jay.sf May 03 '20 at 05:32
  • @HannahMiriamDancy Perhaps you will find some alternatives here: https://stats.stackexchange.com/a/238675/163114 – jay.sf May 03 '20 at 05:35
  • 1
    Thank you for your help - it's unfortunate to see that it has not been addressed, especially seeing the forum post you linked is from almost a year ago. I've been trying mixor out, which is being...difficult, and will look at MCMCglmm and brms as well. – Hannah Miriam Dancy May 03 '20 at 06:06
  • Welcome @HannahMiriamDancy. I don't know if its worth to bump the issue in github. Good luck with the alternatives, feel free to publish an alternative here if you are successful! – jay.sf May 03 '20 at 06:10
  • 1
    If I find an alternative, I will definitely update. Thank you again. – Hannah Miriam Dancy May 03 '20 at 13:52
  • Does anyone have an update about getting predictions from clmm? – confusedindividual Aug 20 '22 at 16:33