Ordinal Logistic Regression In R

此生再无相见时 提交于 2019-12-25 00:27:47

问题


I am working on a dataset where my target variable CLASS has three categorical values.

Now When I apply Ordinal Logistic Regression and run the polr command. 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?

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


回答1:


Please provide a reproducible data. Anyway, generating some data with an unordered dependent variable Class does not give me this error. 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. 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?



来源:https://stackoverflow.com/questions/55416164/ordinal-logistic-regression-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!