【问题标题】:polr(..) ordinal logistic regression in Rpolr(..)R中的序数逻辑回归
【发布时间】:2013-07-24 05:46:37
【问题描述】:

我在使用 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 个级别的信息(除了我描述的那种数据之外什么都不包含)

所以我问的是一个可怕的问题,因为我不能给你我的完整数据集,而且我不知道问题出在哪里。多亏了这些信息,你能猜出我的问题出在哪里吗?

谢谢

【问题讨论】:

  • 101 个级别很可能是您的问题。用这样的因素拟合模型不会有太大用处。您需要重新考虑如何组织数据。
  • glm.fit 的警告解释为here,这可能就是优化失败的原因。

标签: r regression formulas ordinal logistics


【解决方案1】:

orm from rms 可以处理具有大量类别的有序结果。

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

【讨论】:

    【解决方案2】:

    根据@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 
    

    【讨论】:

      猜你喜欢
      • 2019-08-20
      • 2018-01-26
      • 1970-01-01
      • 2018-02-12
      • 2014-06-20
      • 2021-11-13
      • 1970-01-01
      • 2014-06-26
      • 2021-05-02
      相关资源
      最近更新 更多