R中的序数逻辑回归 [英] Ordinal Logistic Regression In R

查看:102
本文介绍了R中的序数逻辑回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

现在当我应用序数逻辑回归并运行 polr 命令时.它显示此错误尝试找到合适的起始值失败".我认为我的目标变量没有排序.有人能告诉我如何排列有序值的 Sv 吗?

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

<块引用>

polr(Class ~ ., data = training, Hess = TRUE) 中的错误:尝试找到合适的起始值失败另外:警告消息:1:glm.fit:算法没有收敛 2:glm.fit:拟合概率数字上发生了 0 或 1

解决方案

请提供可重现的数据.无论如何,使用无序因变量 Class 生成一些数据不会给我这个错误.看这里:

# polr 函数的库图书馆(大量")# 样本大小为 30n <- 30# 生成一个大小为 n 且每个级别为 n/3 的频率的因子Class <- factor(rep(c("HIGH", "LOW", "MEDIUM"), each= n/3))# 使用 # 使其成为无序因子(代码未运行)# Class <-ordered(Class, levels= c("LOW", "MEDIUM", "HIGH"))# 生成一个带有两个随机变量的数据框set.seed(1)训练 <- data.frame(matrix(rnorm(2*n), ncol=2))# 将因变量 Class 添加到 te 数据框training$Class <- 类# 运行模型m <- polr(Class~., data= training, Hess = TRUE)# 查看系数和测试图书馆(AER")系数(米)

这表明因子顺序不是问题.事实上,询问谷歌在 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)

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

解决方案

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中的序数逻辑回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆