Calling predict after training with polr on multicollinear data problematic

1.6k views Asked by At

Take a look at the code below. This question has been asked before but shut down - presumably for lack of R code to reproduce the problem.

Basically, when there is multicollinearity in the data, using Polr-trained model is problematic during the call to predict(). What am I missing here?

The part in bold below is what R says to me. The rest is my code.

r = c(2,2,2,3,3,3,1,1,1,1)
r = as.factor(r)
x = c(0,0,0,4,5,6,0,-1,-1,1)
y = c(5,5,2,1,0,3,10,4,3,8)
z = c(0,0,0,4,5,6,0,-1,-1,1)
a = data.frame(r,x,y,z)

library(MASS)
model <- polr(r~x+z, data=a, Hess=TRUE)

Warning message: In polr(r ~ x + z, data = a, Hess = TRUE) : design appears to be rank-deficient, so dropping some coefs

test = model.frame(r~x+ z, data=a)
predict(model, test, type="class", s=model$lambda.min)

Error in X %*% object$coefficients : non-conformable arguments

test2 = model.frame(r~x, data=a)
predict(model, test2, type="class", s=model$lambda.min)

Error in X %*% object$coefficients : non-conformable arguments

test3 = model.frame(~x, data=a)
predict(model, test2, type="class", s=model$lambda.min)

Error in X %*% object$coefficients : non-conformable arguments

model2 = polr(r~x, data=a, Hess=TRUE)
predict(model2, test, type="class", s=model$lambda.min)

[1] 1 1 1 3 3 3 1 1 1 2
Levels: 1 2 3

predict(model2, test2, type="class", s=model$lambda.min)

[1] 1 1 1 3 3 3 1 1 1 2
Levels: 1 2 3

predict(model2, test3, type="class", s=model$lambda.min)

[1] 1 1 1 3 3 3 1 1 1 2
Levels: 1 2 3

0

There are 0 answers