首页 > 解决方案 > 如何修复 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 模型,这对我来说也是必要的。

标签: rmlogit

解决方案


推荐阅读