当我尝试将Ordered Logit模型拟合到较长的数据集时,这些函数将返回错误Error in solve.default(H, g[!fixed]): system is computationally singular: reciprocal condition number = 3.64628e-18
。
我见过this,但是数据不再可用,因此无法解决问题。另外,尝试this one和this one失败。
复制我正在使用的数据集的代码是:
# 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模型,这对我来说也是必需的。