2

看看下面的代码。这个问题之前已经被问过,但被关闭了——大概是因为缺少 R 代码来重现问题。

基本上,当数据中存在多重共线性时,在调用predict(). 我在这里想念什么?

下面的粗体部分是 R 对我说的。剩下的是我的代码。

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)

警告消息:在 polr(r ~ x + z, data = a, Hess = TRUE) 中:设计似乎排名不足,因此删除了一些系数

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

X %*% object$coefficients 中的错误:参数不一致

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

X %*% object$coefficients 中的错误:参数不一致

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

X %*% object$coefficients 中的错误:参数不一致

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
等级:1 2 3

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

[1] 1 1 1 3 3 3 1 1 1 2
等级:1 2 3

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

[1] 1 1 1 3 3 3 1 1 1 2
等级:1 2 3

4

0 回答 0