R中的polr(..)有序logistic回归

R中的polr(..)有序logistic回归,r,regression,formulas,ordinal,logistics,R,Regression,Formulas,Ordinal,Logistics,我在使用polr功能时遇到一些问题 以下是我掌握的数据子集: # response variable rep = factor(c(0.00, 0.04, 0.06, 0.13, 0.15, 0.05, 0.07, 0.00, 0.06, 0.04, 0.05, 0.00, 0.92, 0.95, 0.95, 1, 0.97, 0.06, 0.06, 0.03, 0.03, 0.08, 0.07, 0.04, 0.08, 0.03, 0.07, 0.05, 0.05, 0.06, 0.04, 0

我在使用polr功能时遇到一些问题

以下是我掌握的数据子集:

# response variable
rep = factor(c(0.00, 0.04, 0.06, 0.13, 0.15, 0.05, 0.07, 0.00, 0.06, 0.04, 0.05, 0.00, 0.92, 0.95, 0.95, 1, 0.97, 0.06, 0.06, 0.03, 0.03, 0.08, 0.07, 0.04, 0.08, 0.03, 0.07, 0.05, 0.05, 0.06, 0.04, 0.04, 0.08, 0.04, 0.04, 0.04, 0.97, 0.03, 0.04, 0.02, 0.04, 0.01, 0.06, 0.06, 0.07, 0.08, 0.05, 0.03, 0.06,0.03))
# "rep" is discrete variable which represents proportion so that it varies between 0 and 1
# It is discrete proportions because it is the proportion of TRUE over a finite list of TRUE/FALSE. example: if the list has 3 arguments, the proportions value can only be 0,1/3,2/3 or 1

# predicted variable
set.seed(10)
pred.1 = sample(x=rep(1:5,10),size=50)
pred.2 = sample(x=rep(c('a','b','c','d','e'),10),size=50)
# "pred" are discrete variables 

# polr
polr(rep~pred.1+pred.2)
我给你的子集很好用!但是我的整个数据集和其中的一些子集都不起作用!在我的数据中,除了数量之外,我找不到任何与这个子集不同的东西。因此,我的问题是:在级别数量方面是否存在任何限制,例如,会产生以下错误消息:

Error in optim(s0, fmin, gmin, method = "BFGS", ...) : 
  the initial value in 'vmin' is not finite
以及通知信息:

   glm.fit: fitted probabilities numerically 0 or 1 occurred
(我必须将这两条信息翻译成英语,这样它们可能不是100%正确)

有时我只收到通知消息,有时一切都正常,这取决于我使用的数据子集

我的rep变量总共有101个级别的信息(只包含我描述的数据类型)

所以我问的是一个很糟糕的问题,因为我无法提供完整的数据集,我不知道问题出在哪里。由于这些信息,你能猜出我的问题来自哪里吗


谢谢你

根据@joran的建议,你的问题可能是100级因素,我将推荐一些可能在统计上不有效但在你的特定情况下仍然有效的方法:根本不要使用逻辑回归。放下它。执行简单的线性回归,然后根据需要使用专门的四舍五入程序对输出进行离散化。试一试,看看它对你有多好

rep.v = c(0.00, 0.04, 0.06, 0.13, 0.15, 0.05, 0.07, 0.00, 0.06, 0.04, 0.05, 0.00, 0.92, 0.95, 0.95, 1, 0.97, 0.06, 0.06, 0.03, 0.03, 0.08, 0.07, 0.04, 0.08, 0.03, 0.07, 0.05, 0.05, 0.06, 0.04, 0.04, 0.08, 0.04, 0.04, 0.04, 0.97, 0.03, 0.04, 0.02, 0.04, 0.01, 0.06, 0.06, 0.07, 0.08, 0.05, 0.03, 0.06,0.03)

set.seed(10)
pred.1 = factor(sample(x=rep(1:5,10),size=50))
pred.2 = factor(sample(x=rep(c('a','b','c','d','e'),10),size=50))

model = lm(rep.v~as.factor(pred.1) + as.factor(pred.2))
output = predict(model, newx=data.frame(pred.1, pred.2))

# Here's one way you could accomplish the discretization/rounding
f.levels = unique(rep.v)
rounded = sapply(output, function(x){ 
  d = abs(f.levels-x)
  f.levels[d==min(d)]
  }
)

>rounded

   1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24 
0.06 0.07 0.00 0.06 0.15 0.00 0.07 0.00 0.13 0.06 0.06 0.15 0.15 0.92 0.15 0.92 0.15 0.15 0.06 0.06 0.00 0.07 0.15 0.15 
  25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48 
0.15 0.15 0.00 0.00 0.15 0.00 0.15 0.15 0.07 0.15 0.00 0.07 0.15 0.00 0.15 0.15 0.00 0.15 0.15 0.15 0.92 0.15 0.15 0.00 
  49   50 
0.13 0.15 
orm
from可以处理大量类别的有序结果

library(rms)
orm(rep ~ pred.1 + pred.2)

101级很可能是你的问题。用这样的因子拟合模型不会有多大用处。您需要重新考虑如何组织数据。解释了来自
glm.fit
的警告,这可能就是优化失败的原因。