R中的序数Logistic回归

时间:2019-03-29 11:10:23

标签: r regression

我正在处理一个数据集,其中我的目标变量CLASS具有三个分类值。 HIGH,LOW AND MEDIUM

现在,当我应用序数逻辑回归并运行polr命令时。其显示此错误“试图找到合适的起始值失败”。我认为我的目标变量没有排序。有人可以告诉我如何安排有序值的Sv吗?

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

polr中的错误(类〜。,数据=训练,赫斯= TRUE):尝试   查找合适的起始值失败此外:警告消息:1:   glm.fit:算法未收敛2:glm.fit:拟合概率   数字发生0或1

1 个答案:

答案 0 :(得分:0)

Please provide a reproducible data.无论如何,使用无序因变量Class生成一些数据不会给我这个错误。看到这里:

# 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) 

这表明因素顺序不是问题。确实,问谷歌向我展示了类似的glm错误,那是关于收敛而不是关于因子顺序。这可能使问题重复。参见此处,例如Why am I getting "algorithm did not converge" and "fitted prob numerically 0 or 1" warnings with glm?