![](/img/trans.png)
[英]Error in mlogit: Error in solve.default(H, g[!fixed]) : system is computationally singular: reciprocal condition number = 3.4767e-18
[英]How to solve mlogit Error in solve.default(H, g[!fixed]) : system is computationally singular: reciprocal condition number = 3.03549e-18?
我有一個寬格式數據,我正在調用mlogit.data
我嘗試使用 mlogit package 實現混合 logit model,我有一個熱編碼的分類列(顏色,大小組)是否導致以下錯誤?
model_data 中的數值特征經過 log1p 轉換。
Complete.choice <- mlogit.data(model_data, choice = "y",
varying = 2:79, shape = "wide", sep = "__", id = "customer_id")
formula <- as.formula("y ~ price + weight + length + height + width + color_white +
color_red + color_black + size_group_1 + size_group_3 + size_group_5 +
size_group_4 + size_group_2 | -1")
# rpar
features <- c("price","weight","length","height","width","color_white",
"color_red","color_black" ,"size_group_1",
"size_group_3","size_group_5","size_group_4","size_group_2" )
random_parameter <- rep("n", 1:length(features))
names(random_parameter) <- features
sample.mxl <- mlogit(formula, Complete.choice , rpar = random_parameter,
R = 40, halton = NA, panel = TRUE, seed = 123, print.level = 0)
Error in solve.default(H, g[!fixed]) :
system is computationally singular: reciprocal condition number = 3.23485e-18
錯誤的意思是Hessian矩陣是奇異的,即行列式為零,逆矩陣不存在。 實際上,您無法獲得方差-協方差矩陣。
發生這種情況的原因有多種:
R=40
。 這是一個非常低的數字。 它將對混合 Logit 概率的多維積分給出較差的近似值。 隨着 model 的復雜性、可用的替代品等的增加,所需的抽獎次數也在增加。許多人認為 500-1000 是好的,而其他人傾向於使用 5000 或更高。 我,我從 1000 開始,逐漸增加到我的參數穩定的地方。 繪制太少也可能導致您看到的錯誤。如果不對實際數據進行測試,就不可能診斷出原因,但這些至少是一些可以幫助您入門的指示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.