R mlogit 模型,计算奇异

R mlogit model, computationally singular

我今天一整天都在努力格式化我的 data (在通过 BondedDust 的 table(TM) 建议发现错误后更新) 适合 mLogit:

raw <-read.csv("C:\Users\Andy\Desktop\research\Oxford\Prefs\rData.csv", header=T, row.names = NULL,id="id")
raw <-na.omit(raw)

library(mlogit)

TM <- mlogit.data(raw, choice = "selected", shape = "long", alt.var = "dishId", chid.var = "individuals", drop.index = TRUE)

我失败的地方是尝试为我的数据建模。

model <- mlogit(selected ~ food + plate | sex + age +hand, data = TM)

Error in solve.default(H, g[!fixed]) : system is computationally singular: reciprocal condition number = 6.26659e-18

我真的很想在这个话题上得到一些帮助。恐怕我会有点生气。

数据本身来自一项实验,我们让 1000 人在两盘食物之间做出决定(我们改变食物的外观 - Angular 或圆形 - 并改变盘子的形状- 是 Angular 或循环)。

致以最良好的祝愿, 安迪.

PS 恐怕我是 Whosebug 上有统计问题的新手。

与其说这是一个答案,不如说这是一个评论(我没有足够的代表点数来发表评论!)。但是,我无法重现您的代码,因为您的 rData.csv.

中没有任何 age

该模型无法将您的 dishId 解释为替代索引 (alt.var),因为您有不同的密钥对用于不同的选择。例如,您将 "TS" 和 "RS" 作为 .csv 文件中第一个选项的替代索引键,但您将 "RR" 和 "RS" 作为选项 3634 的键。另外,您也没有指定备选方案的名称 (alt.levels)。由于 alt.levels 未填写,mlogit.data 将自动尝试根据替代索引检测替代项, 它无法正确解释 .这基本上就是一切出错的地方:'food' 和 'plate' 变量没有被解释为替代方案,而是被视为最终导致奇点问题的个别特定变量。

您有两种选择来解决此问题。您可以通过 alt.levels 参数将实际替代方案作为 mlogit.data 的输入:

TM <- mlogit.data(raw, choice = "selected", shape = "long", alt.levels = c("food","plate"),chid.var = "individuals",drop.index=TRUE)
model1 <- mlogit(selected ~ food + plate | sex + age +hand, data = TM)

或者,您可以选择使索引键保持一致,以便您可以通过 alt.var 将它们作为输入提供。 mlogit.data 现在可以正确猜出您的备选方案是什么:

raw[,3] <- rep(1:2,nrow(raw)/2) # use 1 and 2 as unique alternative keys for all choices
TM <- mlogit.data(raw, choice = "selected", shape = "long", alt.var="dishId", chid.var = "individuals")
model2 <- model <- mlogit(selected ~ food + plate | sex + age +hand, data = TM)

我们验证这两个模型确实相同。模型一的结果:

> summary(model1)

Call:
mlogit(formula = selected ~ food + plate | sex + age + hand, 
    data = TM, method = "nr", print.level = 0)

Frequencies of alternatives:
   food   plate 
0.42847 0.57153 

nr method
4 iterations, 0h:0m:0s 
g'(-H)^-1g = 0.00423 
successive function values within tolerance limits 

Coefficients :
                    Estimate Std. Error t-value  Pr(>|t|)    
plate:(intercept) -0.0969627  0.0764117 -1.2689 0.2044589    
foodCirc           1.0374881  0.0339559 30.5540 < 2.2e-16 ***
plateCirc         -0.0064866  0.0524547 -0.1237 0.9015835    
plate:sexmale     -0.0811157  0.0416113 -1.9494 0.0512512 .  
plate:age16-34     0.1622542  0.0469167  3.4583 0.0005435 ***
plate:age35-54     0.0312484  0.0555634  0.5624 0.5738492    
plate:age55-74     0.0556696  0.0836248  0.6657 0.5055987    
plate:age75+       0.1057646  0.2453797  0.4310 0.6664508    
plate:handright   -0.0177260  0.0539510 -0.3286 0.7424902    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log-Likelihood: -8284.6
McFadden R^2:  0.097398 
Likelihood ratio test : chisq = 1787.9 (p.value = < 2.22e-16)

与模型 2 的结果对比。请注意,备选方案已正确识别,但名称未明确添加到模型中:

> summary(model2)

Call:
mlogit(formula = selected ~ food + plate | sex + age + hand, 
    data = TM, method = "nr", print.level = 0)

Frequencies of alternatives:
      1       2 
0.42847 0.57153 

nr method
4 iterations, 0h:0m:0s 
g'(-H)^-1g = 0.00423 
successive function values within tolerance limits 

Coefficients :
                Estimate Std. Error t-value  Pr(>|t|)    
2:(intercept) -0.0969627  0.0764117 -1.2689 0.2044589    
foodCirc       1.0374881  0.0339559 30.5540 < 2.2e-16 ***
plateCirc     -0.0064866  0.0524547 -0.1237 0.9015835    
2:sexmale     -0.0811157  0.0416113 -1.9494 0.0512512 .  
2:age16-34     0.1622542  0.0469167  3.4583 0.0005435 ***
2:age35-54     0.0312484  0.0555634  0.5624 0.5738492    
2:age55-74     0.0556696  0.0836248  0.6657 0.5055987    
2:age75+       0.1057646  0.2453797  0.4310 0.6664508    
2:handright   -0.0177260  0.0539510 -0.3286 0.7424902    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log-Likelihood: -8284.6
McFadden R^2:  0.097398 
Likelihood ratio test : chisq = 1787.9 (p.value = < 2.22e-16)