简体   繁体   English

R中的序数Logistic回归

[英]Ordinal Logistic Regression In R

I am working on a dataset where my target variable CLASS has three categorical values. 我正在处理一个数据集,其中我的目标变量CLASS有三个分类值。 高,低和中等

Now When I apply Ordinal Logistic Regression and run the polr command. 现在当我应用Ordinal Logistic回归并运行polr命令时。 Its showing this error "attempt to find suitable starting values failed". 它显示此错误“试图找到合适的起始值失败”。 I think my target variable is not ordered. 我认为我的目标变量没有订购。 Can anybody tell me how to arrange Sv of ordered values? 谁能告诉我如何安排有序值的Sv?

model <- polr(Class~., data= training, Hess = TRUE)

Error in polr(Class ~ ., data = training, Hess = TRUE) : attempt to find suitable starting values failed In addition: Warning messages: 1: glm.fit: algorithm did not converge 2: glm.fit: fitted probabilities numerically 0 or 1 occurred polr出错(Class~。,data = training,Hess = TRUE):尝试找到合适的起始值失败另外:警告消息:1:glm.fit:算法没有收敛2:glm.fit:拟合概率数字0或1发生

Please provide a reproducible data. 请提供可重复的数据。 Anyway, generating some data with an unordered dependent variable Class does not give me this error. 无论如何,使用无序因变量Class生成一些数据并不会给我这个错误。 See here: 看这里:

# library the package for polr function
library("MASS")

# a sample size of 30
n <- 30

# generating a factor with smple size n and with a frequency for each level of n/3
Class <- factor(rep(c("HIGH", "LOW", "MEDIUM"), each= n/3))

# leaving it an unordered factor by using # (code not run)
# Class <- ordered(Class, levels= c("LOW", "MEDIUM", "HIGH")) 

# generating a data frame with two random variables
set.seed(1)
training <- data.frame(matrix(rnorm(2*n), ncol=2))

# adding the dependent variable Class to te data frame
training$Class <- Class

# running model
m <- polr(Class~., data= training, Hess = TRUE)

# look at coefficients and tests
library("AER") 
coeftest(m) 

This suggests that factor order is not the problem. 这表明要素顺序不是问题。 And indeed, asking google showed me similar errors in glm, that are about convergance not about factor order. 事实上,要求谷歌向我展示了glm中的类似错误,这是关于收敛而不是因素顺序。 This maybe makes the question a duplicate. 这可能使问题重复。 See here, for example Why am I getting "algorithm did not converge" and "fitted prob numerically 0 or 1" warnings with glm? 看到这里,例如为什么我得到“算法没有收敛”和“用数字拟合0或1”警告与glm?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM