Search code examples
rpredictordinal

ordinal::predict.clm not working properly


I am confused why my codes did not work:

library(ordinal)
X_train = matrix(rnorm(25,5,5), 5,5)
colnames(X_train) = paste("Topic", 1:5)
Y_train = as.factor(c(4,2,1,3,2))

result = clm(Y_train ~ X_train)
X_test = matrix(norm(10,5,4),nrow=2,ncol=5)

if I do this: predict(result, X_test, type="class")

The error is:

variable lengths differ (found for 'X_train')

but both X_train and X_test consist of 5 columns(variables) they just differ by the number of observations --- X_train has got 5, while X_test has got 2.

I've tried

setNames(X_test, attr(terms(result),"term.labels"))

the error persists.

And if I instead do this: ordinal::predict.clm(result, X_test, type="class")

I get this error:

Error: 'predict.clm' is not an exported object from 'namespace:ordinal'

but it is indeed a function from this package...

and if I do this:

x = predict(result, X_test)

then x appears to have been assigned this predict.clm function instead of actual calculations...

Could anyone kindly help me out here? Been hung out to dry....


Solution

  • I solved the problem by doing it manually --- calculating the model prediction myself following this post:

    https://stats.stackexchange.com/questions/41006/predicting-ordered-logit-in-r