polr(..)序数逻辑回归在R

polr(..)序数逻辑回归在R

问题描述:

我在使用polr函数时遇到了一些麻烦。polr(..)序数逻辑回归在R

这里是我拥有的数据的一个子集:

# 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%正确的)

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

我代表变量总共有101级水平的信息(并包含没有别的比我所描述的那种数据)

所以它是我问becaue我不能给你一个可怕的问题,我完整的数据集,我不知道问题在哪里。由于这些信息,你能猜出我的问题来自哪里吗?

谢谢

+0

101级很可能是您的问题。用这样一个因素来拟合模型是不会有用的。您需要重新考虑如何组织数据。 – joran

+0

'glm.fit'的警告解释为[这里](http://stackoverflow.com/q/8596160/324364),这可能是为什么优化失败。 – joran

继@ 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 

ormrms可处理命令的结果与大量的类。

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