R:无法拟合 mlogit() 模型,奇点误差

R: can't fit an mlogit() model, singularity error

提问人:RokasR 提问时间:5/26/2023 最后编辑:RokasR 更新时间:5/26/2023 访问量:20

问:

我正在将多项式 Logit 模型拟合到选择数据。当我引入可变性别时,突然间,我无法再拟合模型,因为出现一条错误消息:

Error in solve.default(H, g[!fixed]) : Lapack routine dgesv: system is exactly singular: U[8,8] = 0

这是我的数据集:

Choice dataset

attributes <- expand.grid(
  company = c("Metalac", "NikolaTeslaAirport", "Jedinstvo", "Energoprojekt"),
  return_rate = c(0, 0.05, 0.10, 0.15),
  dividend = c(0, 1.5, 3.0, 4.5, 6),
  trend = c("Trend1", "Trend2", "Trend3")
)

set.seed(123)

gen <- sample(c("male", "female"), size = 100, prob = c(0.3669, 0.6331), replace = TRUE)

df <- data.frame(
  ID = rep(1:100, each = 3), 
  alternative = as.factor(rep(1:3, times = 100)), 
  choice = 0, 
  gender = rep(gen, each = 3),
  attributes[sample(nrow(attributes), size = 100 * 3, replace = TRUE), ]
)

df <- df %>% mutate(
  gender = as.factor(gender),
  company = as.factor(company),
  return_rate = as.numeric(return_rate),
  dividend = as.numeric(dividend),
  trend = as.factor(trend)
)

我试图拟合的模型:

fit2 <- mlogit(choice ~ company + return_rate + dividend + gender, data = df)

不幸的是,我实际上不知道该怎么做。

R 模型拟合 mlogit

评论


答: 暂无答案