问题描述
我正在处理一个数据集,其中我的目标变量 CLASS 具有三个分类值.
现在当我应用序数逻辑回归并运行 polr 命令时.它显示此错误尝试找到合适的起始值失败".我认为我的目标变量没有排序.有人能告诉我如何排列有序值的 Sv 吗?
model
polr(Class ~ ., data = training, Hess = TRUE) 中的错误:尝试找到合适的起始值失败另外:警告消息:1:glm.fit:算法没有收敛 2:glm.fit:拟合概率数字上发生了 0 或 1
解决方案
请提供可重现的数据.无论如何,使用无序因变量 Class 生成一些数据不会给我这个错误.看这里:
# polr 函数的库图书馆(大量")# 样本大小为 30n
这表明因子顺序不是问题.事实上,询问谷歌在 glm 中向我展示了类似的错误,这些错误是关于收敛而不是因子顺序.这可能会使问题重复.参见此处,例如 为什么我得到算法没有收敛"?和在数字上拟合概率为 0 或 1";glm 警告?
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)
解决方案
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?
这篇关于R中的序数逻辑回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!