r - 如何修复 mlogit 错误:“系统在计算上是奇异的:倒数条件数”
问题描述
当我尝试将 Ordered Logit 模型拟合到长数据集时,函数会返回错误Error in solve.default(H, g[!fixed]): system is computationally singular: reciprocal condition number = 3.64628e-18
。
我已经看到了,但数据不再可用,我无法解决我的问题。另外,尝试了这个和这个没有成功。
重现我正在使用的数据集的代码是:
# Example of caracteristic dummies
caract <- tibble::tribble(~CPU, ~RAM,
1, 1,
-1, 1,
1, -1,
-1, -1)
# Weights for choosing the probabilities
weights <- c(0.3954545, 0.2727273, 0.2363636, 0.0954546)
# Simulating the choices block
block <- caract
block$Alternative <- 1:4
# Simulating the dataset
df <- NULL
n_decisors <- 50
set.seed(123456)
i <- 1
for(i in 1:n_decisors){
block$Decisor <- i
block$Choice <- sample(1:4, prob = weights)
df <- rbind(df, block)
}
返回错误的模型拟合过程是:
library(mlogit)
# Creating the model data object
df_mlogit <- mlogit.data(data = df, choice = "Choice",
shape = "long", alt.var = "Alternative",
varying = 1:2, ranked = T)
# Fitting the model
m <- mlogit(formula = Choice ~ CPU + RAM,
rpar = c(CPU = "n", RAM = "n"),
data = df_mlogit)
caract
当我通过从模拟的每次迭代中采样行来使选择块不详尽时,df
不会发生错误,但我需要估计数据是本示例中模拟的格式的情况。另外,我知道nnet::multinom(Choice ~ CPU + RAM, data=df)
解决这个问题,但它不适合混合 logit 模型,这对我来说也是必要的。
解决方案
推荐阅读
- sql - 使用带有 orderBy 子句的连接列
- java - 将 ascii 转换为 int 值
- python - 使用两位数字订购 CSV
- ruby-on-rails - Sass 语法错误:“rgb”的参数数量错误(1 对 3)
- mysql - 使用 PowerShell 的 SQL 连接中的错误
- bootstrap-4 - 当它应该占据行的一半时,bootstrap col 不起作用
- html - 如何在表格中正确放置粘性 td 元素
- php - 获取模态轮播以在已选择的图像上打开
- javascript - 如何从 GITLAB API 中检索信息
- python - 使用 Python 将矩阵简化为梯形练习